tcs34725基于arduino的代码
时间: 2023-05-11 13:04:01 浏览: 172
Arduino_TCS34725_tcs34725arduino_TCS34725_arduino_arduinotcs3472
5星 · 资源好评率100%
以下是一个基于Arduino的TCS34725颜色传感器的示例代码:
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_TCS34725.h>
// 定义TCS34725对象
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);
void setup() {
Serial.begin(9600);
// 初始化TCS34725
if (tcs.begin()) {
Serial.println("Found sensor");
} else {
Serial.println("No TCS34725 found ... check your connections");
while (1);
}
}
void loop() {
uint16_t r, g, b, c;
// 读取颜色值
tcs.getRawData(&r, &g, &b, &c);
// 输出颜色值
Serial.print("R: "); Serial.print(r);
Serial.print(" G: "); Serial.print(g);
Serial.print(" B: "); Serial.print(b);
Serial.print(" C: "); Serial.print(c);
// 计算颜色温度和亮度
float temperature = tcs.calculateColorTemperature(r, g, b);
float lux = tcs.calculateLux(r, g, b);
// 输出颜色温度和亮度
Serial.print(" Color Temperature: "); Serial.print(temperature, 2); Serial.print(" K");
Serial.print(" Lux: "); Serial.print(lux, 2);
delay(500);
}
阅读全文