Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. # Import all necessary libraries
  2. import board
  3. import touchio
  4. from digitalio import DigitalInOut, Direction, Pull
  5. from adafruit_hid.keyboard import Keyboard
  6. from adafruit_hid.keycode import Keycode
  7. from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
  8. import adafruit_dotstar as dotstar
  9. #import time
  10. import neopixel
  11.  
  12. # Change these values for what you want each key to print when pressed
  13. keys_pressed = ["Button 1 ", "Button 2 ", "Button 3 "]
  14.  
  15. # RGB LED code is necessary for disabling the LED since it would otherwise keep its last color
  16. dot = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=1)
  17. dot[0] = 0
  18.  
  19. button1 = DigitalInOut(board.D0) # Pin assignment for button 1
  20. button1.direction = Direction.INPUT
  21. button1.pull = Pull.UP
  22.  
  23. button2 = DigitalInOut(board.D2) # Pin assignment for button 2
  24. button2.direction = Direction.INPUT
  25. button2.pull = Pull.UP
  26.  
  27. screw = board.D4 # Pin assignmnet for side screw
  28. touch = touchio.TouchIn(screw)
  29.  
  30. # Set up keyboard
  31. kbd = Keyboard()
  32. layout = KeyboardLayoutUS(kbd) # Set US layout
  33.  
  34. # Keeps keys from being constantly pressed/released
  35. button1Check=1
  36. button2Check=1
  37. button3Check=0 # Inverted to avoid press at startup
  38.  
  39. ######################### MAIN LOOP ##############################
  40. while True:
  41.  
  42. if not button1.value: # If the button isn't pressed...
  43. if button1Check: # Check value so it only does this once per press
  44. layout.write(keys_pressed[0]) # Print string
  45. button1Check = 0 # Update check value
  46. if button1.value: # If button is pressed...
  47. button1Check = 1 # Update check value
  48.  
  49. if not button2.value:
  50. if button2Check:
  51. layout.write(keys_pressed[1])
  52. button2Check = 0
  53. if button2.value:
  54. button2Check = 1
  55.  
  56. if not touch.value:
  57. if button3Check:
  58. layout.write(keys_pressed[2])
  59. button3Check = 0
  60. if touch.value:
  61. button3Check = 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement