code.py
 1  # SPDX-FileCopyrightText: Copyright (c) 2021 Eva Herrada for Adafruit Industries
 2  #
 3  # SPDX-License-Identifier: Unlicense
 4  import time
 5  
 6  import usb_hid
 7  from adafruit_hid.keyboard import Keyboard
 8  from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
 9  import adafruit_ducky
10  
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  
29  time.sleep(1)  # Sleep for a bit to avoid a race condition on some systems
30  keyboard = Keyboard(usb_hid.devices)
31  keyboard_layout = KeyboardLayoutUS(keyboard)  # We're in the US :)
32  
33  duck = adafruit_ducky.Ducky("duckyscript.txt", keyboard, keyboard_layout)
34  
35  result = True
36  running = False
37  while result is not False:
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()