Страница в процессе наполнения
Для проекта понадобятся:
- Old tube radio – about 100-300$
- Raspberry Pi3b – 35$
- USB Sound card – 2$
- Analog to digital converter for RPi – 3$
- Shaft potentiometer resistor 1K – 0.1$
- Power audio amplifier board with volume control – 0.7$
- Power supply 5V 3A – 4$
- LEDs, resistors, mounts, etc. – 3$
Разбираем и удаляем старые компоненты.
Вставляем новые компоненты…
…и соединяем согласно схемы
код для радио
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
#pip3 install Adafruit-ADS1x15 import Adafruit_ADS1x15 import os, subprocess, time import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(18, GPIO.IN) #list of your radio stations radio_stations={ 1:'http://146.71.124.10:8100', 2:'http://209.9.238.5:8570', 3:"http://solid41.streamupsolutions.com:10099/stream", 4:"http://hazel.torontocast.com:3040", 5:"http://64.150.176.42:8098", 6:"https://streaming02.zfast.co.uk/proxy/ventureradio?mp=/stream.mp3", 7:"http://hazel.torontocast.com:3040", 8:"https://montmartre.ice.infomaniak.ch/montmartre.mp3", 9:"http://solid41.streamupsolutions.com:10099/stream", 10:"http://ice64.securenetsystems.net:80/BILTMORE" } adc = Adafruit_ADS1x15.ADS1115() GAIN = 1 while True: # Read the ADC channel 0 values values = adc.read_adc(0, gain=GAIN) #print(values) if values in range(-100,165): if not os.popen('ps aux | grep mplayer | grep -v grep | head -n1 | sed "s/.*http/http/"').\ read() == radio_stations[1]+'\n': cmd = f'sudo killall -v mplayer ; mplayer {radio_stations[1]} &' subprocess.Popen(cmd, shell = True) if values in range(165,1511): if not os.popen('ps aux | grep mplayer | grep -v grep | head -n1 | sed "s/.*http/http/"').\ read() == radio_stations[2]+'\n': cmd = f'sudo killall -v mplayer ; mplayer {radio_stations[2]} &' subprocess.Popen(cmd, shell = True) if values in range(1511,3214): if not os.popen('ps aux | grep mplayer | grep -v grep | head -n1 | sed "s/.*http/http/"').\ read() == radio_stations[3]+'\n': cmd = f'sudo killall -v mplayer ; mplayer {radio_stations[3]} &' subprocess.Popen(cmd, shell = True) if values in range(3214,5673): if not os.popen('ps aux | grep mplayer | grep -v grep | head -n1 | sed "s/.*http/http/"').\ read() == radio_stations[4]+'\n': cmd = f'sudo killall -v mplayer ; mplayer {radio_stations[4]} &' subprocess.Popen(cmd, shell = True) if values in range(5673,8512): if not os.popen('ps aux | grep mplayer | grep -v grep | head -n1 | sed "s/.*http/http/"').\ read() == radio_stations[5]+'\n': cmd = f'sudo killall -v mplayer ; mplayer {radio_stations[5]} &' subprocess.Popen(cmd, shell = True) if values in range(8512,10990): if not os.popen('ps aux | grep mplayer | grep -v grep | head -n1 | sed "s/.*http/http/"').\ read() == radio_stations[6]+'\n': cmd = f'sudo killall -v mplayer ; mplayer {radio_stations[6]} &' subprocess.Popen(cmd, shell = True) if values in range(10990,12970): if not os.popen('ps aux | grep mplayer | grep -v grep | head -n1 | sed "s/.*http/http/"').\ read() == radio_stations[7]+'\n': cmd = f'sudo killall -v mplayer ; mplayer {radio_stations[7]} &' subprocess.Popen(cmd, shell = True) if values in range(12970,13946): if not os.popen('ps aux | grep mplayer | grep -v grep | head -n1 | sed "s/.*http/http/"').\ read() == radio_stations[8]+'\n': cmd = f'sudo killall -v mplayer ; mplayer {radio_stations[8]} &' subprocess.Popen(cmd, shell = True) if values in range(13946,15119): if not os.popen('ps aux | grep mplayer | grep -v grep | head -n1 | sed "s/.*http/http/"').\ read() == radio_stations[9]+'\n': cmd = f'sudo killall -v mplayer ; mplayer {radio_stations[9]} &' subprocess.Popen(cmd, shell = True) if values in range(15919,17000): if not os.popen('ps aux | grep mplayer | grep -v grep | head -n1 | sed "s/.*http/http/"').\ read() == radio_stations[10]+'\n': cmd = f'sudo killall -v mplayer ; mplayer {radio_stations[10]} &' subprocess.Popen(cmd, shell = True) time.sleep(0.3) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
import Adafruit_ADS1x15 import os, subprocess, time, pygame adc = Adafruit_ADS1x15.ADS1115() GAIN = 1 pygame.mixer.init() pygame.mixer.music.load("radio.mp3") pygame.mixer.music.play(-1) mplayer_run = True this_value = adc.read_adc(0, gain=GAIN) while True: prev_value = this_value this_value = adc.read_adc(0, gain=GAIN) change = (this_value-prev_value)/prev_value #print(change) if abs(change)>0.0009: if mplayer_run == True: cmd = 'sudo killall -v mplayer &' subprocess.Popen(cmd, shell = True) mplayer_run = False #print('kill') pygame.mixer.music.unpause() else: mplayer_run = True time.sleep(0.5) pygame.mixer.music.pause() #print('pause') time.sleep(0.1) |