this page is being edited
For the project you will need:
- 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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
#pip3 install adafruit-circuitpython-ads1x15 import Adafruit_ADS1x15 import os, subprocess, os, time, random radio_stations={ 1:'iden.mp3', 2:'Atomic_Commercial.mp3', 3:'New_Vegas.mp3', 4:'Atomic_Radio.mp3', 5:'top_10.mp3', 6:'appalachia_radio_fallout_76_with_dj_julie.mp3', 7:"https://montmartre.ice.infomaniak.ch/montmartre.mp3", 8:'fallout_76_appalachia_radio_complete.mp3', 9:'i_don_t_want_to_set_the_world_on_fire.mp3' } path = '/home/pi/radio/radio_stations/' adc = Adafruit_ADS1x15.ADS1115() GAIN = 1 while True: # Read all the ADC channel values in a list. values = adc.read_adc(0, gain=GAIN) #print(values) if values in range(-100,1360): if not os.popen('ps aux | grep mplayer | grep -v grep | head -n1 | sed "s/.*\///"').read() == radio_stations[1]+'\n': random.seed() rand = random.randint(0, 1200) cmd = f'sudo killall -v mplayer ; mplayer -ss {rand} {path}{radio_stations[1]} &' subprocess.Popen(cmd, shell = True) if values in range(1361,4186): if not os.popen('ps aux | grep mplayer | grep -v grep | head -n1 | sed "s/.*\///"').read() == radio_stations[2]+'\n': random.seed() rand = random.randint(0, 1200) cmd = f'sudo killall -v mplayer ; mplayer -ss {rand} {path}{radio_stations[2]} &' subprocess.Popen(cmd, shell = True) if values in range(4188,6372): if not os.popen('ps aux | grep mplayer | grep -v grep | head -n1 | sed "s/.*\///"').read() == radio_stations[3]+'\n': random.seed() rand = random.randint(0, 1200) cmd = f'sudo killall -v mplayer ; mplayer -ss {rand} {path}/{radio_stations[3]} &' subprocess.Popen(cmd, shell = True) if values in range(6373,8036): if not os.popen('ps aux | grep mplayer | grep -v grep | head -n1 | sed "s/.*\///"').read() == radio_stations[4]+'\n': random.seed() rand = random.randint(0, 1200) cmd = f'sudo killall -v mplayer ; mplayer -ss {rand} {path}{radio_stations[4]} &' subprocess.Popen(cmd, shell = True) if values in range(8037,9645): if not os.popen('ps aux | grep mplayer | grep -v grep | head -n1 | sed "s/.*\///"').read() == radio_stations[5]+'\n': random.seed() rand = random.randint(0, 1000) cmd = f'sudo killall -v mplayer ; mplayer -ss {rand} {path}{radio_stations[5]} &' subprocess.Popen(cmd, shell = True) if values in range(9646,11259): if not os.popen('ps aux | grep mplayer | grep -v grep | head -n1 | sed "s/.*\///"').read() == radio_stations[6]+'\n': random.seed() rand = random.randint(0, 500) cmd = f'sudo killall -v mplayer ; mplayer -ss {rand} {path}{radio_stations[6]} &' subprocess.Popen(cmd, shell = True) if values in range(11260,13365): if not os.popen('ps aux | grep mplayer | grep -v grep | head -n1 | sed "s/.*\///"').read() == radio_stations[7]+'\n': random.seed() rand = random.randint(0, 500) cmd = f'sudo killall -v mplayer ; mplayer -ss {rand} {path}{radio_stations[7]} &' subprocess.Popen(cmd, shell = True) if values in range(13366,15795): if not os.popen('ps aux | grep mplayer | grep -v grep | head -n1 | sed "s/.*\///"').read() == radio_stations[8]+'\n': random.seed() rand = random.randint(0, 500) cmd = f'sudo killall -v mplayer ; mplayer -ss {rand} {path}{radio_stations[8]} &' subprocess.Popen(cmd, shell = True) if values in range(15796,30000): if not os.popen('ps aux | grep mplayer | grep -v grep | head -n1 | sed "s/.*\///"').read() == radio_stations[9]+'\n': random.seed() rand = random.randint(0, 50) cmd = f'sudo killall -v mplayer ; mplayer -ss {rand} {path}{radio_stations[9]} &' 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 28 29 30 31 32 33 34 |
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) |