forked from ese-detkin-lab/ese5190-2022-lab1-firefly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab_1_4,4.py
46 lines (40 loc) · 1.32 KB
/
lab_1_4,4.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import time
import board
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
keys_pressed = [Keycode.A, Keycode.B,Keycode.C,Keycode.D,Keycode.BACKSPACE]
control_key = Keycode.SHIFT
time.sleep(1) # Sleep for a bit to avoid a race condition on some systems
keyboard = Keyboard(usb_hid.devices)
keyboard_layout = KeyboardLayoutUS(keyboard)
i2c = board.STEMMA_I2C()
i2c = board.STEMMA_I2C()
apds = APDS9960(i2c)
apds.enable_proximity = True
apds.enable_color = True
apds.enable_gesture = True
apds.color_integration_time=10
print("waiting to type stuff")
while True:
r, g, b, c = apds.color_data
gesture = apds.gesture()
if gesture == 0x01:
keyboard.press(control_key,keys_pressed[0])
keyboard.release_all()
elif gesture == 0x02:
keyboard.press(control_key,keys_pressed[1])
keyboard.release_all()
elif gesture == 0x03:
keyboard.press(control_key,keys_pressed[2])
keyboard.release_all()
elif gesture == 0x04:
keyboard.press(control_key,keys_pressed[3])
keyboard.release_all()
if r>150:
keyboard.press(control_key,keys_pressed[4])
keyboard.release_all()
if b>150:
break