物联网开发122 - Micropython ESP32 C3连接TCS3200颜色识别传感器模块_tcs3200颜色传感器 esp32

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 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值