CircuitPython Neo Trinkey examples.
This commit is contained in:
parent
5fd9a2e74d
commit
f51f0a4e7a
3 changed files with 78 additions and 0 deletions
25
Adafruit_Neo_Trinkey/cap_touch_hid.py
Normal file
25
Adafruit_Neo_Trinkey/cap_touch_hid.py
Normal file
|
|
@ -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.
|
||||||
41
Adafruit_Neo_Trinkey/cap_touch_neopixel_brightness.py
Normal file
41
Adafruit_Neo_Trinkey/cap_touch_neopixel_brightness.py
Normal file
|
|
@ -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()
|
||||||
12
Adafruit_Neo_Trinkey/neopixel_blink.py
Normal file
12
Adafruit_Neo_Trinkey/neopixel_blink.py
Normal file
|
|
@ -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)
|
||||||
Loading…
Reference in a new issue