while True:
# Check each pin
for key_pin in key_pin_array:
if not key_pin.value:
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
# "Type" the Keycode or string
key = keys_pressed[i]
if isinstance(key, str):
keyboard_layout.write(key)
else:
# If it's not a string...
keyboard.press(control_key, key)
keyboard.release_all()
# Turn off the red LED
led.value = False
time.sleep(0.01)
Connect pin A1 or A2 to ground, using a wire or alligator clip, then disconnect it to send the key press "A" or the string
"Hello world!"
Create the Objects and Variables
First, we assign some variables for later use. We create three arrays assigned to variables:
, and
key_pin_array
keys_pressed
to fill it later. The third is what we would like our "keyboard" to output - in this case the letter "A" and the phrase, "Hello
world!". We create our last variable assigned to
keypress. We'll be using two keypresses, but you can have up to six keypresses at once.
Next
and
keyboard
keyboard_layout
© Adafruit Industries
# Is it grounded?
# Wait for it to be ungrounded!
# Get the corresponding Keycode or string
# If it's a string...
# ..."Release"!
. The first is the pins we're going to use. The second is empty because we're going
control_key
objects are created. We only have US right now (if you make other layouts
https://learn.adafruit.com/adafruit-feather-m4-express-atsamd51
# ...Print the string
# "Press"...
This wiring example shows A1 and A2 connected to
ground.
Remember, on Trinket, A1 and A2 are labeled 2 and 0!
On other boards, you will have A1 and A2 labeled as
expected.
which allows us to later apply the shift key to our
,
keypress_pins
Page 161 of 183
Need help?
Do you have a question about the Feather M4 Express and is the answer not in the manual?