ws28l2b_Init()
Tcs3200_Init()
while True:
Colour()
if name == “main”:
main()
演示效果:
按照提示,进行黑白校准。然后颜色识别模块对着红色纸张后,LED灯就会亮红色。对着蓝色纸张,LED灯就会亮蓝色。
**四、TCS3200驱动**
tcs3200.py
tcs3200.py: a driver for the TCS3200 color sensor
Copyright © U. Raich
Written for the course on the Internet of Things at the
University of Cape Coast, Ghana
The program is released under the MIT licence
from machine import Pin,Timer
import utime as time
class TCS3200(object):
“”"
This class reads RGB values from a TCS3200 colour sensor.
GND Ground.
VDD Supply Voltage (2.7-5.5V)
LED 1: LEDs on, 0: LEDs off
/OE Output enable, active low. When OE is high OUT is disabled
allowing multiple sensors to share the same OUT line.
OUT Output frequency square wave.
S0/S1 Output frequency scale selection.
S2/S3 Colour filter selection.
OUT is a square wave whose frequency is proprtional to the
intensity of the selected filter colour.
S2/S3 selects between red, green, blue, and no filter.
S0/S1 scales the frequency at 100%, 20%, 2% or off.
To take a reading the colour filters are selected in turn for a
fraction of a second and the frequency is read and converted to
Hz.
"""
# class variables
ON = True # on for debugging and the leds
OFF = False # off
RED = (0,0) # S2 and S3 low
BLUE = (0,1) # S2 low, S3 high
GREEN = (1,1) # S2 and S3 high
CLEAR = (1,0) # S2 high and S3 low
RED_COMP = 0 # the color components
GREEN_COMP = 1
BLUE_COMP = 2
CLEAR_COMP = 3
POWER_OFF = (0,0) # S0 and S1 low
TWO_PERCENT = (0,1) # S0 low, S1 high
TWENTY_PERCENT = (1,0) # S0 high, S1 low
HUNDRED_PERCENT = (1,1) # S0 and S1 high
WHITE = True
BLACK = False
def __init__(self, OUT=None, S2=None, S3=None, S0=None, S1=None, LED=None,OE=None):
"""
The gpios connected to the sensor OUT, S2, and S3 pins must
be specified. The S0, S1

最低0.47元/天 解锁文章
1741

被折叠的 条评论
为什么被折叠?



