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!"
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.
Create the Objects and Variables
First, we assign some variables for later use. We create three arrays assigned to variables:
keypress_pins
,
key_pin_array
, and
keys_pressed
. The first is the pins we're going to use. The second is empty because we're going
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
control_key
which allows us to later apply the shift key to our
keypress. We'll be using two keypresses, but you can have up to six keypresses at once.
Next
keyboard
and
keyboard_layout
objects are created. We only have US right now (if you make other layouts
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!
# "Type" the Keycode or string
key = keys_pressed[i] # Get the corresponding Keycode or string
if isinstance(key, str): # If it's a string...
keyboard_layout.write(key) # ...Print the string
else: # If it's not a string...
keyboard.press(control_key, key) # "Press"...
keyboard.release_all() # ..."Release"!
# Turn off the red LED
led.value = False
time.sleep(0.01)
© Adafruit Industries
https://learn.adafruit.com/adafruit-feather-m4-express-atsamd51
Page 161 of 183
Содержание Feather M4 Express
Страница 1: ...Adafruit Feather M4 Express Created by lady ada Last updated on 2019 03 04 10 41 14 PM UTC...
Страница 5: ...Adafruit Industries https learn adafruit com adafruit feather m4 express atsamd51 Page 10 of 183...
Страница 58: ...Adafruit Industries https learn adafruit com adafruit feather m4 express atsamd51 Page 63 of 183...
Страница 164: ...Adafruit Industries https learn adafruit com adafruit feather m4 express atsamd51 Page 169 of 183...
Страница 168: ...Adafruit Industries https learn adafruit com adafruit feather m4 express atsamd51 Page 173 of 183...