# a boolean that indicates if it was a double tap. You might see both a single # and double tap! def tap_data(single, double): if single: print('Single click!') if double: print('Double click!') # Stream tap data for 2 seconds, then pause for 5 seconds and stream forever. print('Streaming tap data for 2 seconds...') board.start_tap(tap_data) time.sleep(2.0) print('Pausing for 5 seconds...') board.stop_tap() time.sleep(5.0) try: # Wait in a loop to receive tap data from the board in the background. print('Printing tap data (Ctrl-C to quit)...') board.start_tap(tap_data) while True: time.sleep(1.0) finally: print('Stopping!') board.stop_tap() # Close Firmata board connection when done. board.close()
# to higher brightness because the color information is 'lost'. It's best to # just call set brightness once at the start to set a good max brightness instead # of trying to make animations with it. board.set_pixel_brightness(50) # Animate moving the colors across the pixels 100 times / 10 seconds. print('Animating pixels for 10 seconds...') for offset in range(100): # Go through each pixel and set its color based on its position and the # current offset. Constrain these values to fall within the list of colors. for i in range(10): # Find the color for this pixel. color = colors[(i+offset)%len(colors)] # Set the pixel color. board.set_pixel(i, color[0], color[1], color[2]) # Push the updated colors out to the pixels (this will make the pixels change # their color, the previous set_pixel calls just change the memory and not # the pixels). board.show_pixels() # Sleep for a bit between iterations. time.sleep(0.1) # Clear all the pixels to turn them off. board.clear_pixels() board.show_pixels() # Make sure to call show after clear! time.sleep(0.1) # Small delay to make sure board connection doesn't close # before previous command is processed. # Close Firmata board connection when done. board.close()