tcs34725颜色传感器arduino代码
时间: 2023-05-11 14:05:10 浏览: 52
以下是tcs34725颜色传感器的Arduino代码:
#include <Wire.h>
#include <Adafruit_TCS34725.h>
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);
void setup() {
Serial.begin(9600);
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:\t"); Serial.print(r);
Serial.print(" G:\t"); Serial.print(g);
Serial.print(" B:\t"); Serial.print(b);
Serial.print(" C:\t"); Serial.print(c);
// Calculate color temperature using utility functions. Note that
// these are not accurate, and should be used only as a rough estimate.
// For more accurate results, use the equation specified in the
// datasheet to calculate color temperature
Serial.print(" Color Temp:\t"); Serial.print(tcs.calculateColorTemperature(r, g, b));
Serial.print(" K - ");
// Calculate lux using utility functions. Note that these are not
// accurate, and should be used only as a rough estimate. For more
// accurate results, use the equations specified in the datasheet.
Serial.print("Lux:\t"); Serial.print(tcs.calculateLux(r, g, b));
Serial.print(" - ");
Serial.println();
delay(250);
}
希望这可以帮到你!