forked from ese-detkin-lab/ese5190-2022-lab1-firefly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4.4 code.py
70 lines (60 loc) · 1.83 KB
/
4.4 code.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import time
import analogio
import board
import digitalio
import usb_hid
import neopixel
from adafruit_apds9960.apds9960 import APDS9960
from adafruit_apds9960 import colorutility
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) # We're in the US :)
i2c = board.STEMMA_I2C()
apds = APDS9960(i2c)
apds.enable_color = True
pixels = neopixel.NeoPixel(board.NEOPIXEL, 1)
while True:
# wait for color data to be ready
while not apds.color_data_ready:
time.sleep(0.005)
# get the data and print the different channels
r, g, b, c = apds.color_data
print("red: ", r)
print("green: ", g)
print("blue: ", b)
a = [r,g,b]
x=max(a)
time.sleep(0.1)
#decide color
if r == x :
keyboard.press(Keycode.R)
keyboard.release_all()
keyboard.press(Keycode.E)
keyboard.release_all()
keyboard.press(Keycode.D)
keyboard.release_all()
if g == x:
keyboard.press(Keycode.G)
keyboard.release_all()
keyboard.press(Keycode.R)
keyboard.release_all()
keyboard.press(Keycode.E)
keyboard.release_all()
keyboard.press(Keycode.E)
keyboard.release_all()
keyboard.press(Keycode.N)
keyboard.release_all()
if b == x:
keyboard.press(Keycode.B)
keyboard.release_all()
keyboard.press(Keycode.L)
keyboard.release_all()
keyboard.press(Keycode.U)
keyboard.release_all()
keyboard.press(Keycode.E)
keyboard.release_all()
# 在这里写上你的代码 :-)