Skip to content

Commit

Permalink
Merge pull request #1 from loretod/main
Browse files Browse the repository at this point in the history
HID Keyboard CP Version
  • Loading branch information
milador authored May 1, 2023
2 parents b964dd4 + a89bfb8 commit a60218f
Show file tree
Hide file tree
Showing 17 changed files with 104 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file added Build_Files/.DS_Store
Binary file not shown.
Binary file added Build_Files/Software_Files/.DS_Store
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CircuitPython
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"python.languageServer": "Pylance",
"python.linting.pylintEnabled": false
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# SPDX-FileCopyrightText: 2018 Kattni Rembor for Adafruit Industries
#
# SPDX-License-Identifier: MIT
# Modified by: Loreto Dumitrescu
# CircuitPython code for the Rocket Switch Interface designed by Milad from Makers Making Change.
# Project Details: https://makersmakingchange.com/project/rocket-switch-interface/

"""CircuitPython Rocket Switch Interface- Keyboard"""
import time

import board
import digitalio
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode

# The pins we'll use, each will have an internal pullup
keypress_pins = [board.ROTA, board.SWITCH]
# Our array of key objects
key_pin_array = []
# The Keycode sent for each button
# To view a complete list of available keycodes:
# https://docs.circuitpython.org/projects/hid/en/latest/_modules/adafruit_hid/keycode.html
keys_pressed = [Keycode.TAB, Keycode.SPACE]

# The keyboard object!
time.sleep(1) # Sleep for a bit to avoid a race condition on some systems
keyboard = Keyboard(usb_hid.devices)
keyboard_layout = KeyboardLayoutUS(keyboard) # We're in the US :)

# Make all pin objects inputs with pullups
for pin in keypress_pins:
key_pin = digitalio.DigitalInOut(pin)
key_pin.direction = digitalio.Direction.INPUT
key_pin.pull = digitalio.Pull.UP
key_pin_array.append(key_pin)

# Creates an instance of the on board light and sets it as an output
led = digitalio.DigitalInOut(board.NEOPIXEL)
led.direction = digitalio.Direction.OUTPUT

print("Waiting for key pin...")

while True:
# Check each pin
for key_pin in key_pin_array:
if not key_pin.value: # Is it grounded?
i = key_pin_array.index(key_pin)
print("Pin #%d is grounded." % i)

# Turn on the red LED
led.value = True

while not key_pin.value:
pass # Wait for it to be ungrounded!
key = keys_pressed[i] # Get the keycode to press
keyboard.press(key) # "Press"...
keyboard.release_all() # ..."Release"!

# Turn off the red LED
led.value = False

time.sleep(0.01)
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# CircuitPython Installation

To install the CircuitPython Code:

1. Download the following files and folders:

- code.py
- adafruit_hid folder
- adafruit-circuitpython...uf2

2. If you haven't installed CircuitPython to the board previously, double-click the reset button on the board to enter bootloader mode. Drag the .uf2 files into the BOOT drive that appears.

3. Drag and drop the code.py file into the drive.

4. Drag the adafruit_hid folder into the lib folder in the drive.

Note: If you are on a Mac and receive a memory error, you may need to copy the folder using command line instead of dragging and dropping. You will need to:

- Open the Terminal app
- Navigate to the location of the folder most likely you'll need to enter: </br>
```cd Downloads```

- To copy the entire folder and internal files type: </br>
```cp -rX adafruit-hid /Volumes/CIRCUITPY/lib```

You should now be able to see the adafruit-hid folder inside the lib folder.

That's it! Your Rocket Switch Interface will now send a Tab and Space when your connected switches are pressed.

If you'd like to change the keys being sent:
1. visit the [Adafruit HID Documentation](https://docs.circuitpython.org/projects/hid/en/latest/_modules/adafruit_hid/keycode.html) for the complete list of keycodes.

2. Open the ```code.py``` file in a simple text editor or better yet a code editor if you have one installed.
3. Type the desired keycode on line number 25 replacing the TAB or SPACE.
4. Save your file and the updates will automatically be applied.

0 comments on commit a60218f

Please sign in to comment.