Text Editor
Adafruit recommends using the Mu editor for editing your CircuitPython code. You can get more info in this guide.
Alternatively, you can use any text editor that saves simple text files
Download the Project Bundle
Your project will use a specific set of CircuitPython libraries, and the code.py file. To get everything you need, click on the Download Project Bundle link below, and uncompress the .zip file.
Plug your Kee Boar board into your computer with a known good USB cable with both data and power wires. It should show up as a thumb drive in your File Explorer or Finder (depending on your operating system) named CIRCUITPY.
Drag the contents of the uncompressed bundle directory onto your Key Boar board CIRCUITPY drive, replacing any existing files or directories with the same names, and adding any new ones that are necessary.
# SPDX-FileCopyrightText: 2024 John Park & Tyeth Gundry for Adafruit Industries # # SPDX-License-Identifier: MIT ''' DOOM launch for Windows 'zdoom.exe' for Windows https://zdoom.org/downloads must be in CIRCUITPY/zdoom directory. extract https://github.com/fragglet/squashware/releases squashware-1.1.zip, rename to 'doom1.wad', place in same CIRCUITPY/zdoom directory as the .exe. ''' import time import board from digitalio import DigitalInOut, Direction import keypad import neopixel import usb_hid from adafruit_hid.keyboard import Keyboard from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS from adafruit_hid.keycode import Keycode keys = keypad.Keys((board.A1,), value_when_pressed=False, pull=True) # set up NeoKey launch button kbd = Keyboard(usb_hid.devices) # create keyboard object layout = KeyboardLayoutUS(kbd) led = DigitalInOut(board.D13) # on-board LED led.direction = Direction.OUTPUT led.value = True pixel = neopixel.NeoPixel(board.A2, 1, auto_write=False, brightness=1.0) # NeoKey LED pixel.fill(0x440000) pixel.show() def launch_terminal(): # function for launching local DOOM kbd.send(Keycode.GUI, Keycode.R) # open run cmd time.sleep(0.25) # pylint: disable=line-too-long layout.write("powershell -c \"& { gwmi win32_logicaldisk -f 'DriveType=2' | % { try { $p = $_.DeviceID + 'zdoom\\zdoom.exe'; if (Test-Path $p) { Start-Process $p; break } } catch {} } }\"") time.sleep(0.25) kbd.send(Keycode.ENTER) time.sleep(2) while True: event = keys.events.get() # check for keypress if event: if event.pressed: pixel.fill(0xff0000) # brighten LED pixel.show() launch_terminal() # launch DOOM if event.released: pixel.fill(0x440000) # dim LED pixel.show()
import time import board from digitalio import DigitalInOut, Direction import keypad import neopixel import usb_hid from adafruit_hid.keyboard import Keyboard from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS from adafruit_hid.keycode import Keycode
Button and LED Setup
-
Button: Connected to pin
A1
. This button will be used to trigger the DOOM launch. - Keyboard Object: Creates a virtual keyboard to send keystrokes to the PC.
- LED: On-board LED is turned on initially.
- NeoPixel: A single NeoPixel LED is used for visual feedback.
How the Code Works
When you press the button connected to board.A1
, the script will use the virtual keyboard to open the Run dialog on a Windows PC, execute a PowerShell command to locate and launch zdoom.exe
, and provide visual feedback through the NeoPixel LED. The LED turns bright red when the button is pressed, and dims when it is released.
Imports and Setup
-
time
: For delays in the script. -
board
: Provides access to board-specific pins. -
digitalio
: For controlling digital input/output pins. -
keypad
: To handle button presses. -
neopixel
: To control the NeoPixel LED. -
usb_hid
: For USB HID devices. -
adafruit_hid
: Libraries for emulating keyboard input.
keys = keypad.Keys((board.A1,), value_when_pressed=False, pull=True) kbd = Keyboard(usb_hid.devices) layout = KeyboardLayoutUS(kbd) led = DigitalInOut(board.D13) led.direction = Direction.OUTPUT led.value = True pixel = neopixel.NeoPixel(board.A2, 1, auto_write=False, brightness=1.0) pixel.fill(0x440000) pixel.show()
Function to Launch DOOM
-
Open Run Dialog: Sends
GUI+R
(Windows key + R) to open the Run dialog. -
Powershell Command: Uses PowerShell to search for the
zdoom.exe
file in a specific directory (CIRCUITPY/zdoom
). - Launch DOOM: If the file is found, it starts the DOOM executable.
def launch_terminal(): kbd.send(Keycode.GUI, Keycode.R) time.sleep(0.25) layout.write("powershell -c \"& { gwmi win32_logicaldisk -f 'DriveType=2' | % { try { $p = $_.DeviceID + 'zdoom\\zdoom.exe'; if (Test-Path $p) { Start-Process $p; break } } catch {} } }\"") time.sleep(0.25) kbd.send(Keycode.ENTER) time.sleep(2)
Main Loop
- Check for Key Press: Continuously checks if the button is pressed.
- LED Feedback: Changes the NeoPixel color to indicate whether the button is pressed (bright red) or released (dim red).
-
Launch DOOM: Calls
launch_terminal()
when the button is pressed.
while True: event = keys.events.get() if event: if event.pressed: pixel.fill(0xff0000) pixel.show() launch_terminal() if event.released: pixel.fill(0x440000) pixel.show()
Text editor powered by tinymce.