Final tweaks
This commit is contained in:
parent
70d63cddb8
commit
d54534d891
2 changed files with 19 additions and 22 deletions
|
|
@ -1,7 +1,7 @@
|
|||
# CircuitPython demo - Keyboard emulator
|
||||
|
||||
import time
|
||||
from digitalio import DigitalInOut, Direction, Pull
|
||||
import digitalio
|
||||
import board
|
||||
from adafruit_hid.keyboard import Keyboard
|
||||
from adafruit_hid.keycode import Keycode
|
||||
|
|
@ -24,13 +24,13 @@ keyboard_layout = KeyboardLayoutUS(keyboard) # We're in the US :)
|
|||
|
||||
# Make all pin objects inputs with pullups
|
||||
for pin in keypress_pins:
|
||||
key_pin = DigitalInOut(pin)
|
||||
key_pin.direction = Direction.INPUT
|
||||
key_pin.pull = Pull.UP
|
||||
key_pin = digitalio.DigitalInOut(pin)
|
||||
key_pin.direction = digitalio.Direction.INPUT
|
||||
key_pin.pull = digitalio.Pull.UP
|
||||
key_pin_array.append(key_pin)
|
||||
|
||||
led = DigitalInOut(board.D13)
|
||||
led.direction = Direction.OUTPUT
|
||||
led = digitalio.DigitalInOut(board.D13)
|
||||
led.direction = digitalio.Direction.OUTPUT
|
||||
|
||||
print("Waiting for key pin...")
|
||||
|
||||
|
|
@ -39,21 +39,20 @@ while True:
|
|||
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 grounded." % i)
|
||||
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 released!
|
||||
# Type the Keycode or string
|
||||
pass # Wait for it to be ungrounded!
|
||||
# "Type" the Keycode or string
|
||||
key = keys_pressed[i] # Get the corresponding Keycode or string
|
||||
# if type(key) is str:
|
||||
if isinstance(key, str):
|
||||
keyboard_layout.write(key)
|
||||
else:
|
||||
keyboard.press(control_key, key) # Press...
|
||||
keyboard.release_all() # ...Release!
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,21 +1,19 @@
|
|||
import time
|
||||
from analogio import AnalogIn
|
||||
import analogio
|
||||
import board
|
||||
import digitalio
|
||||
from adafruit_hid.mouse import Mouse
|
||||
from adafruit_hid.keyboard import Keyboard
|
||||
|
||||
mouse = Mouse()
|
||||
keyboard = Keyboard()
|
||||
|
||||
x_axis = AnalogIn(board.A0)
|
||||
y_axis = AnalogIn(board.A1)
|
||||
x_axis = analogio.AnalogIn(board.A0)
|
||||
y_axis = analogio.AnalogIn(board.A1)
|
||||
select = digitalio.DigitalInOut(board.A2)
|
||||
select.direction = digitalio.Direction.INPUT
|
||||
select.pull = digitalio.Pull.UP
|
||||
|
||||
pot_max = 3.29
|
||||
pot_min = 0.00
|
||||
pot_max = 3.29
|
||||
step = (pot_max - pot_min) / 20.0
|
||||
|
||||
|
||||
|
|
@ -23,7 +21,7 @@ def get_voltage(pin):
|
|||
return (pin.value * 3.3) / 65536
|
||||
|
||||
|
||||
def steps(axis): # Maps the potentiometer voltage range from 0-20 in whole numbers
|
||||
def steps(axis): # Maps the potentiometer voltage range to 0-20 in whole numbers
|
||||
return round((axis - pot_min) / step)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue