def show_pressure(): # Makes sure scrollphat buffer is clear sphd.clear() # Pressure value is fetched from weather module pressurevalue = (weather.pressure()) # Uses say_value() to speak the current pressure value speakpressure = ("The current pressure is " + str(round(pressurevalue / 1000, 1)) + " kilopascals") print(speakpressure) say_value(x=speakpressure) # Writes the currnet pressure value to scrollphat buffer sphd.write_string("Pressure: " + str(round(pressurevalue / 1000, 1)) + " kPa", brightness=0.25) # Length of buffer is calculated length = sphd.get_buffer_shape()[0] - 17 # Scrolls for the total length value for x in range(length): sphd.show() sphd.scroll(1) time.sleep(0.03) # Sleeps for 1 second once complete time.sleep(1) # Clears buffer and runs show() to clear display sphd.clear() sphd.show() # Makes sure all button LED's are turned off touchphat.all_off()
def unlock(): global locked global moving global autoModeEnabled moving = True print("Unlocking...") touchphat.all_off() GPIO.output(bcmPinForward, GPIO.HIGH) GPIO.output(bcmPinBackward, GPIO.LOW) for i in range(6): print(i) touchphat.led_on(i) if (i > 0 and i < 5): if (autoModeEnabled and i - 1 in autoModeLeds): pass else: touchphat.led_off(i - 1) time.sleep(1.8) GPIO.output(bcmPinForward, GPIO.LOW) GPIO.output(bcmPinBackward, GPIO.LOW) time.sleep(0.5) GPIO.output(bcmPinForward, GPIO.LOW) GPIO.output(bcmPinBackward, GPIO.HIGH) time.sleep(6 * 1.0) GPIO.output(bcmPinForward, GPIO.LOW) GPIO.output(bcmPinBackward, GPIO.LOW) locked = False print("Door \033[92mUNLOCKED\033[0m") updateLights() moving = False
def show_temp(): # Makes sure scrollphat buffer is clear sphd.clear() # Declares local variable "degrees", fetches value form weather module and rounds to 1 decimal place degrees = round(weather.temperature(), 1) # Section that controls speach output # "speaktemp" string is set speaktemp = ("The temperature is currently " + str(degrees) + " degrees celcius") print(speaktemp) # "speaktemp" is passed into say_value() function say_value(speaktemp) # Section taht controls scrollphat output # "temperature" string is set temperature = (' Temp: ' + str(degrees) + 'C') # "temperature" string is written to sphd buffer sphd.write_string(temperature, brightness=0.25) # Length of buffer is calculated length = sphd.get_buffer_shape()[0] - 17 # Scrolls for the total length value for x in range(length): sphd.show() sphd.scroll(1) time.sleep(0.03) # Sleeps for 1 second once complete time.sleep(1) # Clears buffer and runs show() to clear display sphd.clear() sphd.show() # Makes sure all button LED's are turned off touchphat.all_off()
def show_light(): # Makes sure scrollphat buffer is clear sphd.clear() # variable is set to be the current light value lightvalue = light.light() # Uses say_value() to speak the current light level speaklight = ("The current light level is " + str(lightvalue)) print(speaklight) say_value(x=speaklight) # Light value is stored in scrollphat buffer lightoutput = (" Light: " + str(lightvalue)) sphd.write_string(lightoutput, brightness=0.25) # Length of buffer is calculated length = sphd.get_buffer_shape()[0] - 17 # Scrolls for the total length value for x in range(length): sphd.show() sphd.scroll(1) time.sleep(0.03) # Sleeps for 1 second once complete time.sleep(1) # Clears buffer and runs show() to clear display sphd.clear() sphd.show() # Makes sure all button LED's are turned off touchphat.all_off()
def show_datetime(): # Makes sure scrollphat buffer is clear sphd.clear() # Current date/time is stored in "currentDT" variable currentDT = datetime.datetime.now() # Prints the current time value print(currentDT.strftime("%I:%M %p")) # Uses say_value() to speak the current time speaktime = ("It is currently " + str(currentDT.strftime("%I:%M %p"))) print(speaktime) say_value(speaktime) sphd.write_string("Time: " + str(currentDT.strftime("%I:%M %p")), brightness=0.25) # Length of buffer is calculated length = sphd.get_buffer_shape()[0] - 17 # Scrolls for the total length value for x in range(length): sphd.show() sphd.scroll(1) time.sleep(0.03) # Sleeps for 1 second once complete time.sleep(1) # Clears buffer and runs show() to clear display sphd.clear() sphd.show() # Makes sure all button LED's are turned off touchphat.all_off()
def show_news(): # Makes sure scrollphat buffer is clear sphd.clear() # Uses get_headline() to fetch the NewsAPI JSON document content = get_headline() # Current date/time is stored in "currentDT" variable currentDT = datetime.datetime.now() # Below voice output is split into three parts to ensure gaps in speech # Uses say_value() to say an intro line that includes current time introvoice = ('The current BBC news headline as of ' + str(currentDT.strftime("%I:%M %p"))) say_value(introvoice) # Uses say_value() to speak the title from first article in the JSON file speaknewstitle = (content['articles'][0]['title']) print(speaknewstitle) say_value(speaknewstitle) # Uses say_value() to speak the description from first article in the JSON file speaknewsdesc = (content['articles'][0]['description']) print(speaknewsdesc) say_value(speaknewsdesc) # Makes sure all button LED's are turned off touchphat.all_off()
def unlock(): global pwm global locked global moving global autoModeEnabled moving = True print("Unlocking...") touchphat.all_off() for i in range(6): print(i) if(i < 4): pwm.ChangeDutyCycle(UNLOCK_POS_DUTY_CYCLE) else: pwm.ChangeDutyCycle(NEUTRAL_POS_DUTY_CYCLE) touchphat.led_on(i) if(i > 0 and i < 5): if(autoModeEnabled and i - 1 in autoModeLeds): pass else: touchphat.led_off(i - 1) time.sleep(0.15) pwm.ChangeDutyCycle(0) locked = False print("Door \033[92mUNLOCKED\033[0m") updateLights() moving = False
def show_altitude(): # Makes sure scrollphat buffer is clear sphd.clear() # Altitude value is fetched from weather module altitudevalue = weather.altitude(qnh=1032) # If statement controls if speach output will say "below" or "above" sea level if (altitudevalue <= 0): sealevel = " meters below sea level" elif (altitudevalue >= 1): sealevel = " meters above sea level" # Uses say_value() to speak the current atititude speakaltitude = ("You are roughly " + str(int(altitudevalue)) + sealevel) print(speakaltitude) say_value(x=speakaltitude) # Writes the current sphd.write_string("Altitude: " + str(int(altitudevalue)) + "m", brightness=0.25) # Length of buffer is calculated length = sphd.get_buffer_shape()[0] - 17 # Scrolls for the total length value for x in range(length): sphd.show() sphd.scroll(1) time.sleep(0.03) # Sleeps for 1 second once complete time.sleep(1) # Clears buffer and runs show() to clear display sphd.clear() sphd.show() # Makes sure all button LED's are turned off touchphat.all_off()
def gameOverAnimation(color=WHITE, animationSpeed=50): # play all beeps at once, then flash the background origSurf = DISPLAYSURF.copy() flashSurf = pygame.Surface(DISPLAYSURF.get_size()) flashSurf = flashSurf.convert_alpha() BEEP1.play() # play all four beeps at the same time, roughly. BEEP2.play() BEEP3.play() BEEP4.play() r, g, b = color for i in range(3): # do the flash 3 times for start, end, step in ((0, 255, 1), (255, 0, -1)): # The first iteration in this loop sets the following for loop # to go from 0 to 255, the second from 255 to 0. for alpha in range(start, end, animationSpeed * step): # animation loop # alpha means transparency. 255 is opaque, 0 is invisible checkForQuit() flashSurf.fill((r, g, b, alpha)) DISPLAYSURF.blit(origSurf, (0, 0)) DISPLAYSURF.blit(flashSurf, (0, 0)) drawButtons() pygame.display.update() touchphat.all_on() FPSCLOCK.tick(FPS) touchphat.all_off()
def unlock(): global MOVEMENT_TIME_SEC global pwm global locked global moving global autoModeEnabled moving = True print("Unlocking...") touchphat.all_off() GPIO.output(RELAY_PIN, True) pwm.ChangeDutyCycle(UNLOCK_POS_DUTY_CYCLE) for i in range(6): if (i == 5): pwm.ChangeDutyCycle(0) elif (i == 4): GPIO.output(RELAY_PIN, False) time.sleep(MOVEMENT_TIME_SEC / 6.0) touchphat.led_on(i) if (i > 0 and i < 5): if (autoModeEnabled and i - 1 in AUTO_MODE_LEDS): pass else: touchphat.led_off(i - 1) locked = False print("Door \033[92mUNLOCKED\033[0m") updateLights() moving = False
def beep(key): """ 動作非受付時のアニメーション """ touchphat.all_off() touchphat.led_on(key) time.sleep(0.9) touchphat.all_off()
def animation(): touchphat.all_off() for i in range(1, 7): touchphat.led_on(i) time.sleep(0.05) for i in range(1, 7): touchphat.led_off(i) time.sleep(0.05)
def blink(key): touchphat.all_off() for i in range(0, 3): touchphat.led_off(key) time.sleep(0.1) touchphat.led_on(key) time.sleep(0.1) touchphat.all_off()
def touch_B(event): touchphat.all_off() time.sleep(0.25) touchphat.led_on('B') print("Now playing: WBGO") jc = cast.media_controller jc.play_media('http://wbgo.streamguys.net/wbgo', 'audio/mp3') jc.pause() jc.play()
def touch_A(event): touchphat.all_off() time.sleep(0.25) touchphat.led_on('A') print("Now playing: KEXP Seattle") mc = cast.media_controller mc.play_media('http://live-aacplus-64.kexp.org/kexp64.aac', 'audio/mp3') mc.pause() mc.play()
def touch_C(event): touchphat.all_off() time.sleep(0.25) touchphat.led_on('C') print("Now playing: WFPK Louisville") cc = cast.media_controller cc.play_media('http://lpm.streamguys1.com/wfpk-web', 'audio/mp3') cc.pause() cc.play()
def handle_d(longPress): if longPress: christmas() else: os.system('mpc clear') os.system('mpc ls |mpc add') os.system('mpc play') touchphat.all_off() touchphat.led_on("D")
def handle_b(longPress): if longPress: center() else: os.system('mpc clear') os.system('mpc findadd genre Rock') os.system('mpc findadd genre Blues') os.system('mpc play') touchphat.all_off() touchphat.led_on("B")
def handle_a(longPress): if longPress: k2000() else: os.system('mpc clear') os.system('mpc findadd genre Metal') os.system('mpc findadd genre \'Hard Rock\'') os.system('mpc findadd genre Classical') os.system('mpc play') touchphat.all_off() touchphat.led_on("A")
def blink(key): """ 動作受付時の点滅アニメーション """ touchphat.all_off() for i in range(0, 3): touchphat.led_off(key) time.sleep(0.1) touchphat.led_on(key) time.sleep(0.1) touchphat.all_off()
def animation(): """ 動作開始時のアニメーション """ touchphat.all_off() for i in range(1, 7): touchphat.led_on(i) time.sleep(0.05) for i in range(1, 7): touchphat.led_off(i) time.sleep(0.05)
def wait_for_server(): while True: # wait for server socket try: touchphat.all_on() s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.settimeout(1) s.connect((args.server, args.port)) s.setblocking(False) return s except socket.error: touchphat.all_off() time.sleep(1)
def __init__(self): touchphat.all_off() self.panels = [wemo_panel.WemoPanel(), DummyPanel(), WelcomePanel()] self.panel_index = 0 touchphat.on_release( 1, handler=self.tap ) # the pad index and channel index are off by one :( touchphat.on_release(6, handler=self.tap) # first time startup tasks self.current_panel().on_mount() # mount first panel self.render() # initial render
def handle_c(longPress): if longPress: cycle() else: os.system('mpc clear') os.system('mpc findadd genre Metal') os.system('mpc findadd genre \'Hard Rock\'') os.system('mpc findadd genre Classical') os.system('mpc findadd genre Rock') os.system('mpc findadd genre Blues') os.system('mpc play') touchphat.all_off() touchphat.led_on("C")
def exit_gracefully(signum, frame): global exiting if exiting: return exiting = True log.info("Stopping PiBackup") observer.stop() observer_share.stop() observer.join(2.0) observer_share.join(2.0) touchphat.all_off() log.info("Stopped PiBackup") exit(-1)
def doorHandler(bt_addrs): global threads global presences global autoModeEnabled global present global present_last global kill i = 0 for deviceName in bt_addrs.keys(): presences.append(False) threads.append( threading.Thread(target=updatePresence, args=(i, bt_addrs[deviceName]))) threads[i].start() i += 1 touchphat.all_off() setAutoMode(True) while (True): try: present = False for p in presences: if (p): present = True break print("Present: " + str(present)) if (autoModeEnabled): if (locked and present and not present_last): unlock() elif (not locked and not present and present_last): lock() present_last = present time.sleep(0.5) except KeyboardInterrupt: print("Turning LEDs off") touchphat.all_off() GPIO.cleanup() kill = True GPIO.setmode(GPIO.BCM) GPIO.setup(bcmPinForward, GPIO.OUT) GPIO.setup(bcmPinBackward, GPIO.OUT) GPIO.output(bcmPinForward, GPIO.LOW) GPIO.output(bcmPinBackward, GPIO.LOW) print("Quitting") raise
def christmas(): i = 6 while i > 0: touchphat.all_off() touchphat.led_on(1) touchphat.led_on(3) touchphat.led_on(5) time.sleep(0.24) touchphat.all_off() touchphat.led_on(2) touchphat.led_on(4) touchphat.led_on(6) time.sleep(0.24) i -= 1 global lost lost = True
def display_starting_animation(): """Displays animatation at game start Lights up LEDs in an animation sequence to signal to the player that the game is about to begin. """ time.sleep(0.5) for led in touchphat.NAMES: touchphat.led_on(led) time.sleep(0.1) touchphat.led_off(led) for i in range(3): touchphat.all_on() time.sleep(0.5) touchphat.all_off() time.sleep(0.5)
def handle_touch(event): print('press D event start') for led in range(1,7): touchphat.led_on(led) sleep(0.25) camera.capture('image{0:04d}.jpg'.format(led)) touchphat.led_off(led) sleep(0.25) system('convert -delay 20 -loop 0 image*.jpg animation.gif') touchphat.all_on() sleep(0.25) touchphat.all_off() sleep(0.25) touchphat.all_on() sleep(0.25) touchphat.all_off() print('finished converting to gif animation')
def display_master_sequence(): """Displays master sequence Calls for a new led and displays the current sequence for the player to repeat. Sets the IS_ACCEPTING_INPUT to true to allow the player to press buttons. """ global IS_ACCEPTING_INPUT touchphat.all_off() generate_press() for led in MASTER_SEQUENCE: time.sleep(0.75) touchphat.led_on(led) time.sleep(0.25) touchphat.led_off(led) IS_ACCEPTING_INPUT = True