have string example
This commit is contained in:
parent
b7692eac46
commit
3bf841a306
1 changed files with 19 additions and 16 deletions
|
|
@ -1,37 +1,37 @@
|
||||||
# Gemma IO demo - Keyboard emu
|
# Gemma IO demo - Keyboard emu
|
||||||
|
|
||||||
import digitalio
|
from digitalio import DigitalInOut, Direction, Pull
|
||||||
import touchio
|
import touchio
|
||||||
from board import *
|
import board
|
||||||
import time
|
import time
|
||||||
from adafruit_hid.keyboard import Keyboard
|
from adafruit_hid.keyboard import Keyboard
|
||||||
from adafruit_hid.keycode import Keycode
|
from adafruit_hid.keycode import Keycode
|
||||||
|
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
|
||||||
|
|
||||||
# A simple neat keyboard demo in circuitpython
|
# A simple neat keyboard demo in circuitpython
|
||||||
|
|
||||||
# The button pins we'll use, each will have an internal pullup
|
# The button pins we'll use, each will have an internal pullup
|
||||||
buttonpins = [D2, D0]
|
buttonpins = [board.D2, board.D1, board.D0]
|
||||||
# our array of button objects
|
# our array of button objects
|
||||||
buttons = []
|
buttons = []
|
||||||
# One pin will be capacitive touch
|
|
||||||
ptcbutton = touchio.TouchIn(D1)
|
|
||||||
|
|
||||||
# The keycode sent for each button, will be paired with a control key
|
# The keycode sent for each button, will be paired with a control key
|
||||||
buttonkeys = [Keycode.A, Keycode.B, Keycode.C]
|
buttonkeys = [Keycode.A, Keycode.B, "Hello World!\n"]
|
||||||
controlkey = Keycode.SHIFT
|
controlkey = Keycode.SHIFT
|
||||||
|
|
||||||
# the keyboard object!
|
# the keyboard object!
|
||||||
kbd = Keyboard()
|
kbd = Keyboard()
|
||||||
|
# we're americans :)
|
||||||
|
layout = KeyboardLayoutUS(kbd)
|
||||||
|
|
||||||
# make all pin objects, make them inputs w/pullups
|
# make all pin objects, make them inputs w/pullups
|
||||||
for pin in buttonpins:
|
for pin in buttonpins:
|
||||||
button = digitalio.DigitalInOut(pin)
|
button = DigitalInOut(pin)
|
||||||
button.direction = digitalio.Direction.INPUT
|
button.direction = Direction.INPUT
|
||||||
button.pull = digitalio.Pull.UP
|
button.pull = Pull.UP
|
||||||
buttons.append(button)
|
buttons.append(button)
|
||||||
|
|
||||||
led = digitalio.DigitalInOut(D13)
|
led = DigitalInOut(board.D13)
|
||||||
led.direction = digitalio.Direction.OUTPUT
|
led.direction = Direction.OUTPUT
|
||||||
|
|
||||||
print("Waiting for button presses")
|
print("Waiting for button presses")
|
||||||
|
|
||||||
|
|
@ -47,10 +47,13 @@ while True:
|
||||||
|
|
||||||
while (not button.value):
|
while (not button.value):
|
||||||
pass # wait for it to be released!
|
pass # wait for it to be released!
|
||||||
# type the keycode!
|
# type the keycode or string
|
||||||
k = buttonkeys[i] # get the corresp. keycode
|
k = buttonkeys[i] # get the corresp. keycode/str
|
||||||
kbd.press(controlkey, k)
|
if type(k) is str:
|
||||||
kbd.release_all()
|
layout.write(k)
|
||||||
|
else:
|
||||||
|
kbd.press(controlkey, k) # press...
|
||||||
|
kbd.release_all() # release!
|
||||||
|
|
||||||
# turn off the LED
|
# turn off the LED
|
||||||
led.value = False
|
led.value = False
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue