Last active
July 10, 2018 02:35
-
-
Save waldo323/40b64b41c7adadb7784a776763891b6d to your computer and use it in GitHub Desktop.
clicking a button attached to pin 7 sends space character, used with photo booth software to signal to take a picture.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Itsy Bitsy M0 Express spacebar button | |
# With CircuitPython 3.0 | |
import board | |
import gc | |
import time | |
from digitalio import DigitalInOut, Direction, Pull | |
import adafruit_dotstar | |
gc.collect() # make some rooooom | |
# HID keyboard support | |
from adafruit_hid.keyboard import Keyboard | |
from adafruit_hid.keycode import Keycode | |
# One pixel connected internally! | |
dot = adafruit_dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.5) | |
# Digital input with pullup on D7 | |
buttons = [] | |
for p in [board.D7,]: | |
button = DigitalInOut(p) | |
button.direction = Direction.INPUT | |
button.pull = Pull.UP | |
buttons.append(button) | |
# Used if we do HID output, see below | |
kbd = Keyboard() | |
######################### HELPERS ############################## | |
# Helper to give us a nice color swirl | |
def wheel(pos): | |
# Input a value 0 to 255 to get a color value. | |
# The colours are a transition r - g - b - back to r. | |
if (pos < 0): | |
return [0, 0, 0] | |
if (pos > 255): | |
return [0, 0, 0] | |
if (pos < 85): | |
return [int(pos * 3), int(255 - (pos*3)), 0] | |
elif (pos < 170): | |
pos -= 85 | |
return [int(255 - pos*3), 0, int(pos*3)] | |
else: | |
pos -= 170 | |
return [0, int(pos*3), int(255 - pos*3)] | |
######################### MAIN LOOP ############################## | |
i = 0 | |
while True: | |
# spin internal LED around! autoshow is on | |
dot[0] = wheel(i & 255) | |
if not buttons[0].value: | |
#print("Button D7 pressed!", end ="\t") | |
kbd.press(Keycode.SPACE) | |
kbd.release_all() | |
time.sleep(2) | |
print("") | |
#kbd.press(Keycode.A) | |
kbd.release_all() | |
i = (i+1) % 256 # run from 0 to 255 | |
#time.sleep(0.01) # make bigg er to slow down |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
got rid of a lot of left over code from the demos this was taken from.