def touchenter(): global roomnumber, allwhite b.set_group(roomnumber, allwhite, transitiontime=0) time.sleep(defaultwaittime) touchphat.led_off("Enter") touchphat.led_on("Back")
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 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 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 handle_touch(event): print('press a event start') for led in range(1,7): touchphat.led_on(led) sleep(0.25) touchphat.led_off(led) camera.capture(photo_name)
def beep(key): """ 動作非受付時のアニメーション """ touchphat.all_off() touchphat.led_on(key) time.sleep(0.9) touchphat.all_off()
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 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 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 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 k2000(): i = 2 while i > 0: for pad in ['Back', 'A', 'B', 'C', 'D', 'Enter', 'D', 'C', 'B', 'A']: touchphat.led_on(pad) time.sleep(0.12) touchphat.led_off(pad) i -= 1 global lost lost = True
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 dose_C(event): print (event.name) global manual_mode manual_mode=True time.sleep(0.1) touchphat.led_on("C") touchphat.led_off("A") touchphat.led_off("B") touchphat.led_off("D")
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 dose_B(event): print (event.name) global target_weight global manual_mode manual_mode=False target_weight=19.5 time.sleep(0.1) touchphat.led_on("B") touchphat.led_off("A") touchphat.led_off("C") touchphat.led_off("D")
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 touchback(): global inalert, roomnumber if not inalert: lampon = islampon() inalert = True if lampon: b.set_group(roomnumber, 'on', False) touchphat.led_off("Back") else: b.set_group(roomnumber, 'on', True) touchphat.led_on("Back") time.sleep(1) inalert = False
def dose_D(event): print (event.name) global off_pressed touchphat.led_on("D") touchphat.led_off("A") touchphat.led_off("B") touchphat.led_off("C") time.sleep(0.1) if off_pressed: sb.call('sudo shutdown -h now',shell=True) off_pressed=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
def main(): log.info("Starting PiBackup") global next_lychee_sync observer = get_observer_for_cards() observer_share = get_observer_for_share() monitor_usb_devices() touchphat.led_on(BUTTON_POWER) 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) signal.signal(signal.SIGINT, exit_gracefully) signal.signal(signal.SIGTERM, exit_gracefully) while True: try: time.sleep(1) log if next_lychee_sync and next_lychee_sync < datetime.now(): next_lychee_sync = None sync_lychee() except (KeyboardInterrupt, SystemExit): break except: log.exception("Unable to synchronize Lychee") exit_gracefully(None, None)
def flashButtonAnimation(color, animationSpeed=50): if color == YELLOW: sound = BEEP1 flashColor = BRIGHTYELLOW rectangle = YELLOWRECT led = 2 elif color == BLUE: sound = BEEP2 flashColor = BRIGHTBLUE rectangle = BLUERECT led = 3 elif color == RED: sound = BEEP3 flashColor = BRIGHTRED rectangle = REDRECT led = 4 elif color == GREEN: sound = BEEP4 flashColor = BRIGHTGREEN rectangle = GREENRECT led = 5 origSurf = DISPLAYSURF.copy() flashSurf = pygame.Surface((BUTTONSIZE, BUTTONSIZE)) flashSurf = flashSurf.convert_alpha() r, g, b = flashColor sound.play() for start, end, step in ((0, 255, 1), (255, 0, -1)): # animation loop for alpha in range(start, end, animationSpeed * step): checkForQuit() DISPLAYSURF.blit(origSurf, (0, 0)) flashSurf.fill((r, g, b, alpha)) DISPLAYSURF.blit(flashSurf, rectangle.topleft) pygame.display.update() touchphat.led_on(led) FPSCLOCK.tick(FPS) DISPLAYSURF.blit(origSurf, (0, 0)) touchphat.led_off(led)
def handle_touch(event): touchphat.led_on("Enter") twitter = Twython( consumer_key, consumer_secret, access_token, access_token_secret ) message = "Selfie-gif at this #PatriotPi #Rjam on a RPi zero with TouchPhat and Camera module" image = open('animation.gif', 'rb') response = twitter.upload_media(media=image) media_id = [response['media_id']] twitter.update_status(status=message, media_ids=media_id) touchphat.led_off("Enter") touchphat.all_on() sleep(0.25) touchphat.all_off() sleep(0.25) touchphat.all_on() sleep(0.25) touchphat.all_off() print('I think it just tweeted. IDK go check it')
def start_release(event): print ('release start') touchphat.led_on("Enter")
def dose_A_release(event): touchphat.led_on("A")