def display_array(data): """ Display a 10-element array of 0-255 values on the speakerphat display """ for n in range(0, 10): set_led(n, data[n]) show()
def test_vumeter(): speed = 20 for i in range(1000): offset = int((math.sin(time.time() * speed) * 5) + 5) speakerphat.clear() speakerphat.set_led(offset, 255) speakerphat.show()
def retune(): config.station += 1 # Assumes there are 7 stations if config.station > 7: config.station = 1 os.system("mpc play " + str(config.station)) # updates the Speaker pHat LEDs to show the station clear() for x in range(config.station): set_led(x, 180) show() # stops the clock subprocess and shows the station on the 7 seg config.proc_Popen.kill() config.segment.clear() config.segment.write_display() config.segment.set_digit(3, config.station) config.segment.write_display() time.sleep(4.0) config.segment.clear() config.segment.write_display() config.proc_Popen # This is the bit that's got me baffled.
def flash(self): for i in range(10): speakerphat.set_led(i, self.status[i]) speakerphat.show()
#!/usr/bin/env python import math import time import sys sys.path.append('../python/') import speakerphat speed = 4 for i in range(1000): offset = int((math.sin(time.time() * speed) * 5) + 5) speakerphat.clear() speakerphat.set_led(offset, 255) speakerphat.show()
def pause_mp3(self): os.system('dbuscontrol.sh pause') for x in range(10): speakerphat.set_led(x, 0) speakerphat.show()
def start_mp3(self, filepath): os.system('omxplayer -o local %s &', filepath) speakerphat.clear() for x in range(10): speakerphat.set_led(x, 255 / (x + 1)) speakerphat.show()
while True: # get state is_playing = pygame.mixer.music.get_busy() tiltState = GPIO.input(tiltswitchPin) # play if tiltState is not 1 and lastTiltState is 1 and is_playing is not True: sfx = random.choice(os.listdir(sfx_path)) pygame.mixer.music.load("%s/%s" % (sfx_path, sfx)) pygame.mixer.music.play() print sfx # lights if is_playing: if active_led == led_count or active_led == 0: led_direction = -led_direction active_led += led_direction led_brightness = 255 else: active_led = 0 led_direction = -1 led_brightness = 0 if led_brightness == 255 else 255 speakerphat.clear() speakerphat.set_led(active_led, led_brightness) speakerphat.show() lastTiltState = tiltState time.sleep(0.5)
set_led(x, 180) show() # stops the clock subprocess and shows the station on the 7 seg config.proc_Popen.kill() config.segment.clear() config.segment.write_display() config.segment.set_digit(3, config.station) config.segment.write_display() time.sleep(4.0) config.segment.clear() config.segment.write_display() config.proc_Popen # This is the bit that's got me baffled. shutdown_btn = Button(17, hold_time=3) shutdown_btn.when_held = shutdown retune_btn = Button(23) retune_btn.when_pressed = retune # starts clock.py config.proc_Popen # sets the Speaker pHat LEDS to indicate the station clear() for x in range(config.station): set_led(x, 128) show() os.system("mpc play " + str(config.station)) pause()