Color Unit
支持以下产品:
MicroPython 应用示例
1# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4 5import os, sys, io 6import M5 7from M5 import * 8from hardware import * 9from unit import ColorUnit 10 11 12title0 = None 13label0 = None 14label1 = None 15label2 = None 16i2c0 = None 17color_0 = None 18 19 20def setup(): 21 global title0, label0, label1, label2, i2c0, color_0 22 23 M5.begin() 24 Widgets.fillScreen(0x222222) 25 title0 = Widgets.Title( 26 "ColorUnit Core2 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18 27 ) 28 label0 = Widgets.Label("lux:", 2, 59, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 29 label1 = Widgets.Label("color:", 2, 114, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 30 label2 = Widgets.Label("saturation:", 2, 166, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 31 32 i2c0 = I2C(0, scl=Pin(33), sda=Pin(32), freq=100000) 33 color_0 = ColorUnit(i2c0) 34 35 36def loop(): 37 global title0, label0, label1, label2, i2c0, color_0 38 M5.update() 39 label0.setText(str((str("Iux:") + str((color_0.get_lux()))))) 40 label1.setText(str((str("color:") + str((color_0.get_color_rgb_bytes()))))) 41 label2.setText(str((str("saturation:") + str((color_0.get_color_s()))))) 42 43 44if __name__ == "__main__": 45 try: 46 setup() 47 while True: 48 loop() 49 except (Exception, KeyboardInterrupt) as e: 50 try: 51 from utility import print_error_msg 52 53 print_error_msg(e) 54 except ImportError: 55 print("please update to latest firmware")
UiFlow2 应用示例:
class ColorUnit
Constructors
Methods
- ColorUnit.set_integration_time(val)
设置传感器的积分时间。
- 参数:
val (float) – :以毫秒为单位的所需积分时间。
- 抛出:
ValueError – 如果积分时间超出允许范围。
UIFLOW2:

- ColorUnit.set_gain(val)
设置传感器的增益。
- 参数:
val (int) – :期望的增益值(1、4、16 或 60)。
- 抛出:
ValueError – 如果增益不是允许的值之一。
UIFLOW2:

- ColorUnit.clear_interrupt()
通过写入中断寄存器来清除传感器的中断状态。
UIFLOW2:

- ColorUnit.get_color_raw()
读取传感器检测到的原始 RGBC 颜色值。
- 返回:
一个包含原始红、绿、蓝和清除(Clear)颜色数据的元组。
UIFLOW2:

- ColorUnit.get_cycles()
获取传感器的持久化周期。
- 返回:
持久化周期数;如果中断被禁用,则为 -1。
UIFLOW2:

- ColorUnit.set_cycles(val)
设置传感器的持久性周期。
- 参数:
val (int) – 持久化循环次数,或设置为 -1 以禁用中断。
- 抛出:
ValueError – 如果该值不是允许的 cycle 值之一。
UIFLOW2:

- ColorUnit.get_min_value()
获取传感器的最小阈值(AILT 寄存器)值。
- 返回:
最小阈值。
UIFLOW2:

- ColorUnit.get_max_value()
获取传感器的最大阈值(AIHT 寄存器)值。
- 返回:
最大阈值。
UIFLOW2:

- ColorUnit.get_glass_attenuation()
获取用于补偿因玻璃存在导致光照水平降低的玻璃衰减系数。
- 返回:
玻璃衰减因子(ga)。
UIFLOW2:

- ColorUnit.set_glass_attenuation(value)
设置用于补偿玻璃存在导致光照水平降低的 Glass Attenuation 系数。
- 参数:
value (float) – :要设置的玻璃衰减系数。必须大于或等于 1。
- 抛出:
ValueError – 如果该值小于 1。
UIFLOW2:





















