Created
April 2, 2021 19:16
-
-
Save keyz182/fac68b8dcb8e1cf7ad2474dfec0a58e1 to your computer and use it in GitHub Desktop.
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
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