Skip to content

Commit 895b61f

Browse files
committed
Updated code for button and touchio control
1 parent c584aa8 commit 895b61f

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

Trinkey_Rubber_Ducky/code.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,46 @@
22
#
33
# SPDX-License-Identifier: Unlicense
44
import time
5+
56
import usb_hid
67
from adafruit_hid.keyboard import Keyboard
78
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
89
import adafruit_ducky
910

11+
import touchio # pylint: disable=unused-import
12+
import board
13+
import neopixel
14+
from digitalio import DigitalInOut, Pull # pylint: disable=unused-import
15+
16+
# Uncomment for Neo Trinkey
17+
touch1 = touchio.TouchIn(board.TOUCH1)
18+
touch2 = touchio.TouchIn(board.TOUCH2)
19+
20+
# Uncomment for NeoKey Trinkey
21+
#button = DigitalInOut(board.SWITCH)
22+
#button.switch_to_input(pull=Pull.DOWN)
23+
#button_state = False
24+
25+
pixels = neopixel.NeoPixel(board.NEOPIXEL, 4)
26+
27+
pixels.fill((0xFFFFFF))
28+
1029
time.sleep(1) # Sleep for a bit to avoid a race condition on some systems
1130
keyboard = Keyboard(usb_hid.devices)
1231
keyboard_layout = KeyboardLayoutUS(keyboard) # We're in the US :)
1332

1433
duck = adafruit_ducky.Ducky("duckyscript.txt", keyboard, keyboard_layout)
1534

1635
result = True
36+
running = False
1737
while result is not False:
18-
result = duck.loop()
38+
#if button.value: # Uncomment for NeoKey Trinkey
39+
if any([touch1.value, touch2.value]): # Uncomment for Neo Trinkey
40+
running = not running
41+
if running:
42+
pixels.fill((0x00FF00))
43+
else:
44+
pixels.fill((0xFF0000))
45+
time.sleep(0.2)
46+
if running:
47+
result = duck.loop()

0 commit comments

Comments
 (0)