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 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 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 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 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 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 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 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 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 func_wrapper(*args, **kwargs): def worker(): return func(*args, **kwargs) led_state = True t = threading.Thread(target=worker, daemon=True) t.start() # Make the button blink while t.is_alive(): touchphat.set_led(led_id, led_state) led_state = not led_state t.join(0.5) # After blinking, turn the LED off touchphat.led_off(led_id)
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): try: dash = subprocess.call(["which pimoroni-dashboard"], stdout=subprocess.PIPE, shell=True) if dash != 1: subprocess.call(["x-terminal-emulator -e pimoroni-dashboard"], shell=True) else: print('Installing Dashboard') subprocess.call(["sudo apt-get install pimoroni"], shell=True) subprocess.call(["x-terminal-emulator -e pimoroni-dashboard"], shell=True) touchphat.led_off('D') print("Dashboard launched") except: print("Something went wrong!")
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 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 stop(event): print (event.name) global dispense global manual_mode global stop_speed global calibration_idx global off_pressed calibration_stop_speed=[1470,1480,1490,1500] if not dispense and manual_mode: stop_speed=calibration_stop_speed[calibration_idx] calibration_idx=(calibration_idx+1)%len(calibration_stop_speed) config = {'stop_speed': stop_speed} with open('config.json', 'w') as f: json.dump(config, f) time.sleep(0.1) touchphat.led_off("Back") dispense=False off_pressed=False
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 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 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 attach_devices(event): subprocess.run( ['ssh', 'colin@COLIN-PC', '/usr/local/bin/attach_mouse_keyb.sh']) touchphat.led_off("Enter")
def detach_devices(event): subprocess.run( ['ssh', 'colin@COLIN-PC', 'sudo', 'virsh', 'start', 'win-10']) touchphat.led_off("A")
def touchd(): huealert(blueAlert) touchphat.led_off("D")
#led can be either a value from 1 to 6 or the pad name #pad names: "Back", "A", "B", "C", "D", and "Enter" def turnonled(led): touchphat.led_on(led) def turnoffled(led): touchphat.led_off(led) def light(duration_sec = None) if duration_sec == None: while True: for led in range(1,7): touchphat.led_on(led) time.sleep(0.25) touchphat.led_off(led) else: t_end = time.time() + duration_sec while time.time() < t_end: for led in range(1,7): touchphat.led_on(led) time.sleep(0.25) touchphat.led_off(led) #pad can be either a value from 1 to 6 or the pad name #pad names: "Back", "A", "B", "C", "D", and "Enter" ''' def set_action(pad,func,*args): @touchphat.on_touch(pad) func(args)
import touchphat import json from pyacaia import AcaiaScale GPIO_PIN=15 ACAIA_MAC='00:1C:97:17:FD:97' sb.call('sudo pigpiod',shell=True) pi = pigpio.pi() #cycle the leds for led in range(1,7): touchphat.led_on(led) time.sleep(0.25) touchphat.led_off(led) with open('config.json', 'r') as f: config = json.load(f) stop_speed=config['stop_speed'] off_pressed=False pi.set_servo_pulsewidth(GPIO_PIN, stop_speed) @touchphat.on_touch("Enter") def start(event): print (event.name, target_weight, manual_mode) global dispense
def stop_release(event): print ('release stop') touchphat.led_off("Back")
def turnoffled(led): touchphat.led_off(led)
def detach_devices(event): subprocess.run([ 'ssh', 'colin@COLIN-PC', 'sudo', 'virsh', 'shutdown', 'win-10-work' ]) touchphat.led_off("D")