Skip to content

Instantly share code, notes, and snippets.

@cmoz
Last active March 30, 2022 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmoz/328a215c8631957d103f6489194e9df1 to your computer and use it in GitHub Desktop.
Save cmoz/328a215c8631957d103f6489194e9df1 to your computer and use it in GitHub Desktop.
#include <Wire.h>
#include "Adafruit_TCS34725.h"
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);
void setup() {
Serial.begin(9600);
Serial.println("Color View Test!");
if (tcs.begin()) {
Serial.println("Found sensor");
} else {
Serial.println("No TCS34725 found");
while (1);
}
}
void loop() {
uint16_t clear, red, green, blue;
tcs.setInterrupt(false);
delay(60);
tcs.getRawData(&red, &green, &blue, &clear);
tcs.setInterrupt(true);
uint32_t sum = clear;
float r, g, b;
r = red;
r /= sum;
g = green;
g /= sum;
b = blue;
b /= sum;
r *= 256; g *= 256; b *= 256;
Serial.print("HEX: \t");
Serial.print((int)r, HEX);
Serial.print((int)g, HEX);
Serial.print((int)b, HEX);
Serial.print("\t \t RGB: \t");
Serial.print((int)r );
Serial.print(" ");
Serial.print((int)g);
Serial.print(" ");
Serial.println((int)b);
Serial.println();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment