#!/usr/bin/env python import explorerhat def toggle_light(channel, event): if channel > 4: return if event == 'press': explorerhat.light[channel - 1].on() if event == 'release': explorerhat.light[channel - 1].off() explorerhat.touch.pressed(toggle_light) explorerhat.touch.released(toggle_light) explorerhat.pause()
def waitForEvent(dummy): print "waiting..." explorerhat.pause()
#!/usr/bin/env python import explorerhat def toggle_light(channel, event): if channel > 4: return if event == 'press': explorerhat.light[channel-1].on() if event == 'release': explorerhat.light[channel-1].off() explorerhat.touch.pressed(toggle_light) explorerhat.touch.released(toggle_light) def handle_input(pin): print(pin.name) explorerhat.input.changed(handle_input) explorerhat.pause()
target_seq.append(led) # Add to sequence for seq_n in target_seq: # Display the sequence for t in range(2): eh.output[seq_n-1].toggle() time.sleep(gap) eh.touch.pressed(wait_for_press) # Wait for player to press buttons eh.touch.released(wait_for_press) countdown = 20 # Amount of time player has for each level waiting = True while waiting: if (len(user_seq) == len(target_seq)) or (countdown == 0): if user_seq == target_seq: # Did the player get it right? waiting = False time.sleep(0.5) print('Correct') eh.light.on() # flash all LEDs to celebrate success eh.output.on() time.sleep(0.4) eh.light.off() eh.output.off() gap = gap* 0.8 # make the next round faster else: waiting = False GameOn = False # Game Over print('Game Over: You reached level: ' + str(level)) eh.pause() # Cleanup time.sleep(1) # Brief pause between levels countdown-=1 # Decrement countdown print countdown # display countdown to console