Created
September 17, 2020 22:05
-
-
Save FoamyGuy/609ea5b7a50892bca92ad94354ac3afc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from board import SCL, SDA | |
import busio | |
from adafruit_apds9960.apds9960 import APDS9960 | |
import usb_hid | |
from adafruit_hid.keyboard import Keyboard | |
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS | |
from adafruit_hid.keycode import Keycode | |
# The keyboard object! | |
time.sleep(1) # Sleep for a bit to avoid a race condition on some systems | |
keyboard = Keyboard(usb_hid.devices) | |
keyboard_layout = KeyboardLayoutUS(keyboard) | |
print("hid connected") | |
i2c = busio.I2C(SCL, SDA) | |
apds = APDS9960(i2c) | |
apds.enable_proximity = True | |
apds.enable_gesture = True | |
# Uncomment and set the rotation if depending on how your sensor is mounted. | |
apds.rotation = 270 # 270 for CLUE | |
while True: | |
gesture = apds.gesture() | |
if gesture == 0x01: | |
print("up") | |
keyboard.press(Keycode.UP_ARROW) # "Press"... | |
keyboard.release_all() # ..."Release"! | |
elif gesture == 0x02: | |
print("down") | |
keyboard.press(Keycode.DOWN_ARROW) # "Press"... | |
keyboard.release_all() # ..."Release"! | |
elif gesture == 0x03: | |
keyboard.press(Keycode.LEFT_ARROW) # "Press"... | |
keyboard.release_all() # ..."Release"! | |
print("left") | |
elif gesture == 0x04: | |
keyboard.press(Keycode.RIGHT_ARROW) # "Press"... | |
keyboard.release_all() # ..."Release"! | |
print("right") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment