From f51f0a4e7ad5e07de58989bf6579a9cc5182a344 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Tue, 13 Apr 2021 19:02:54 -0400 Subject: [PATCH] CircuitPython Neo Trinkey examples. --- Adafruit_Neo_Trinkey/cap_touch_hid.py | 25 +++++++++++ .../cap_touch_neopixel_brightness.py | 41 +++++++++++++++++++ Adafruit_Neo_Trinkey/neopixel_blink.py | 12 ++++++ 3 files changed, 78 insertions(+) create mode 100644 Adafruit_Neo_Trinkey/cap_touch_hid.py create mode 100644 Adafruit_Neo_Trinkey/cap_touch_neopixel_brightness.py create mode 100644 Adafruit_Neo_Trinkey/neopixel_blink.py diff --git a/Adafruit_Neo_Trinkey/cap_touch_hid.py b/Adafruit_Neo_Trinkey/cap_touch_hid.py new file mode 100644 index 000000000..4096471bc --- /dev/null +++ b/Adafruit_Neo_Trinkey/cap_touch_hid.py @@ -0,0 +1,25 @@ +"""CircuitPython Capacitive Touch HID Example for Neo Trinkey""" +import time +import board +import touchio +import usb_hid +from adafruit_hid.keyboard import Keyboard +from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS +from adafruit_hid.keycode import Keycode + +keyboard = Keyboard(usb_hid.devices) +keyboard_layout = KeyboardLayoutUS(keyboard) + +touch1 = touchio.TouchIn(board.TOUCH1) +touch2 = touchio.TouchIn(board.TOUCH2) + +while True: + if touch1.value: # If touch pad 1 is touched... + while touch1.value: # Wait for release... + time.sleep(0.1) + keyboard.send(Keycode.SHIFT, Keycode.A) # Then send key press. + + if touch2.value: # If touch pad 2 is touched... + while touch2.value: # Wait for release... + time.sleep(0.1) + keyboard_layout.write("Hello World!\n") # Then send string. diff --git a/Adafruit_Neo_Trinkey/cap_touch_neopixel_brightness.py b/Adafruit_Neo_Trinkey/cap_touch_neopixel_brightness.py new file mode 100644 index 000000000..170a85b68 --- /dev/null +++ b/Adafruit_Neo_Trinkey/cap_touch_neopixel_brightness.py @@ -0,0 +1,41 @@ +"""CircuitPython Capacitive Touch NeoPixel Brightness Control Exmaple""" +import time +import board +import touchio +import neopixel +from _pixelbuf import colorwheel + +touch1 = touchio.TouchIn(board.TOUCH1) +touch2 = touchio.TouchIn(board.TOUCH2) + +pixels = neopixel.NeoPixel(board.NEOPIXEL, 4, auto_write=False) + + +def rainbow(color_index): + for pixel in range(4): + pixel_index = (pixel * 256 // 4) + color_index + pixels[pixel] = colorwheel(pixel_index & 255) + pixels.show() + + +touched = time.monotonic() +color = 0 +while True: + color = color + 1 + if color > 255: + color = 0 + + rainbow(color) + + if time.monotonic() - touched < 0.15: + continue + if touch1.value: + # Touch pad 1 to increase the brightness. + pixels.brightness += 0.05 + pixels.show() + touched = time.monotonic() + elif touch2.value: + # Touch pad 2 to decrease the brightness. + pixels.brightness -= 0.05 + pixels.show() + touched = time.monotonic() diff --git a/Adafruit_Neo_Trinkey/neopixel_blink.py b/Adafruit_Neo_Trinkey/neopixel_blink.py new file mode 100644 index 000000000..73ce34f2c --- /dev/null +++ b/Adafruit_Neo_Trinkey/neopixel_blink.py @@ -0,0 +1,12 @@ +"""CircuitPython NeoPixel Blink example - blinking the built-in NeoPixels.""" +import time +import board +import neopixel + +pixels = neopixel.NeoPixel(board.NEOPIXEL, 4) + +while True: + pixels.fill((255, 0, 0)) + time.sleep(0.5) + pixels.fill((0, 0, 0)) + time.sleep(0.5)