I have the following code that works just fine from Thonny, saved as code.py to my RGB Keypad.
from pmk import PMK
from pmk.platform.rgbkeypadbase import RGBKeypadBase as Hardware
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode
pmk = PMK(Hardware())
keys = pmk.keys
#pmk.set_all(255, 0, 255)
keyboard = Keyboard(usb_hid.devices)
layout = KeyboardLayoutUS(keyboard)
key0 = keys[0] # Camera 1
key1 = keys[1] # Camera 2
key2 = keys[2] # Camera 3
key3 = keys[3] # Camera 4
key4 = keys[4] # Camera 5
key5 = keys[5] # Camera 6
key6 = keys[6] # Camera 7
key7 = keys[7] # Outlook
key8 = keys[8] # Enviroment Canada
key9 = keys[9]
key10 = keys[10]
key11 = keys[11]
key12 = keys[12]
key13 = keys[13]
key14 = keys[14]
key15 = keys[15]
@pmk.on_press(key0)
def press_handler(key0):
pmk.set_led(0, 0, 0, 255)
keyboard.send(Keycode.GUI, Keycode.ONE)
@pmk.on_press(key1)
def press_handler(key1):
pmk.set_led(1, 0, 0, 255)
keyboard.send(Keycode.GUI, Keycode.TWO)
@pmk.on_press(key2)
def press_handler(key2):
pmk.set_led(2, 0, 0, 255)
keyboard.send(Keycode.GUI, Keycode.THREE)
@pmk.on_press(key3)
def press_handler(key3):
pmk.set_led(3, 0, 0, 255)
keyboard.send(Keycode.GUI, Keycode.FOUR)
@pmk.on_press(key4)
def press_handler(key4):
pmk.set_led(4, 0, 0, 255)
keyboard.send(Keycode.GUI, Keycode.Five)
@pmk.on_press(key5)
def press_handler(key5):
pmk.set_led(5, 0, 0, 255)
keyboard.send(Keycode.GUI, Keycode.SIX)
@pmk.on_press(key6)
def press_handler(key6):
pmk.set_led(6, 0, 0, 255)
keyboard.send(Keycode.GUI, Keycode.SEVEN)
@pmk.on_press(key7)
def press_handler(key7):
pmk.set_led(7, 0, 0, 255)
keyboard.send(Keycode.GUI, Keycode.EIGHT)
@pmk.on_press(key8)
def press_handler(key8):
pmk.set_led(8, 0, 0, 255)
keyboard.send(Keycode.GUI, Keycode.NINE)
@pmk.on_press(key12)
def press_handler(key12):
pmk.set_led(12, 0, 0, 255)
keyboard.send(Keycode.GUI, Keycode.E)
@pmk.on_press(key15)
def press_handler(key15):
pmk.set_led(15, 0, 0, 255)
keyboard.send(Keycode.GUI, Keycode.M)
while True:
# Always remember to call keybow.update()!
pmk.update()
On boot up Device Manager shows USB Serial Device (COM20)
A second USB HID Keyboard Device and a second USB HID-compliant mouse.
And CIRCUITPY drive is visible in File explorer.
Nothing happens when I press the keys on the RGB Keypad though?
If I press the reset button COM20 etc disappear and reappear. Now pressing the buttons on the Keypad works?
What if anything am I doing wrong?