Skip to content

Instantly share code, notes, and snippets.

@keyz182
Created April 2, 2021 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keyz182/fac68b8dcb8e1cf7ad2474dfec0a58e1 to your computer and use it in GitHub Desktop.
Save keyz182/fac68b8dcb8e1cf7ad2474dfec0a58e1 to your computer and use it in GitHub Desktop.
import time
import board
import neopixel
from digitalio import DigitalInOut, Direction, Pull
from adafruit_debouncer import Debouncer
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
led = neopixel.NeoPixel(board.NEOPIXEL, 1)
# Set up a keyboard device.
kbd = Keyboard(usb_hid.devices)
button_cut = DigitalInOut(board.A2)
button_cut.direction = Direction.INPUT
button_cut.pull = Pull.UP
cut = Debouncer(button_cut)
button_copy = DigitalInOut(board.A1)
button_copy.direction = Direction.INPUT
button_copy.pull = Pull.UP
copy = Debouncer(button_copy)
button_paste = DigitalInOut(board.A0)
button_paste.direction = Direction.INPUT
button_paste.pull = Pull.UP
paste = Debouncer(button_paste)
def colorwheel(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 or pos > 255:
return 0, 0, 0
if pos < 85:
return int(255 - pos * 3), int(pos * 3), 0
if pos < 170:
pos -= 85
return 0, int(255 - pos * 3), int(pos * 3)
pos -= 170
return int(pos * 3), 0, int(255 - (pos * 3))
led.brightness = 1
i = 0
while True:
cut.update()
copy.update()
paste.update()
if cut.fell:
kbd.press(Keycode.CONTROL, Keycode.X)
elif cut.rose:
kbd.release(Keycode.CONTROL, Keycode.X)
if copy.fell:
kbd.press(Keycode.CONTROL, Keycode.C)
elif copy.rose:
kbd.release(Keycode.CONTROL, Keycode.C)
if paste.fell:
kbd.press(Keycode.CONTROL, Keycode.V)
elif paste.rose:
kbd.release(Keycode.CONTROL, Keycode.V)
i = (i + 1) % 256 # run from 0 to 255
led.fill(colorwheel(i))
#time.sleep(0.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment