Created
July 1, 2025 13:23
-
-
Save fxprime/9c4dd1e0908235617c6cdad4235a58ab to your computer and use it in GitHub Desktop.
testTCS3200 esp32
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino.h> | |
#define S2 26 /*Define S2 Pin Number of ESP32*/ | |
#define S3 25 /*Define S3 Pin Number of ESP32*/ | |
#define sensorOut 14 /*Define Sensor Output Pin Number of ESP32*/ | |
/*Define int variables*/ | |
int Red = 0; | |
int Green = 0; | |
int Blue = 0; | |
int Clear = 0; | |
int getBlue(); | |
int getGreen(); | |
int getRed(); | |
int getClear(); | |
int rmax, gmax, bmax; | |
int rmin, gmin, bmin; | |
void setup() | |
{ | |
pinMode(S2, OUTPUT); /*Define S2 Pin as a OUTPUT*/ | |
pinMode(S3, OUTPUT); /*Define S3 Pin as a OUTPUT*/ | |
pinMode(sensorOut, INPUT); /*Define Sensor Output Pin as a INPUT*/ | |
Serial.begin(115200); /*Set the baudrate to 115200*/ | |
Serial.print("This is TCS3200 Calibration Code"); | |
rmax = 1100; | |
gmax = 1000; | |
bmax = 870; | |
rmin = 135; | |
gmin = 250; | |
bmin = 270; | |
} | |
void loop() | |
{ | |
Clear = getClear(); | |
Red = map(getRed(), rmax, rmin, 0, 255);; | |
Green = map(getGreen(), gmax, gmin, 0, 255); /*Get the Green Color Value*/ | |
Blue = map(getBlue(), bmax, bmin, 0, 255); /*Get the Blue Color Value*/ | |
Serial.print("Clear Freq = "); | |
Serial.print(Clear); /*Print Clear Color Value on Serial Monitor*/ | |
Serial.print(" "); | |
Serial.print("Red Freq = "); | |
Serial.print(Red); /*Print Red Color Value on Serial Monitor*/ | |
Serial.print(" "); | |
Serial.print("Green Freq = "); | |
Serial.print(Green); /*Print Green Color Value on Serial Monitor*/ | |
Serial.print(" "); | |
Serial.print("Blue Freq = "); | |
Serial.println(Blue); /*Print Blue Color Value on Serial Monitor*/ | |
delay(100); | |
} | |
int getRed() | |
{ | |
digitalWrite(S2, LOW); | |
digitalWrite(S3, LOW); | |
return pulseIn(sensorOut, LOW);; | |
} | |
int getGreen() | |
{ | |
digitalWrite(S2, HIGH); | |
digitalWrite(S3, HIGH); | |
return pulseIn(sensorOut, LOW); | |
} | |
int getBlue() | |
{ | |
digitalWrite(S2, LOW); | |
digitalWrite(S3, HIGH); | |
return pulseIn(sensorOut, LOW); ; | |
} | |
int getClear() | |
{ | |
digitalWrite(S2, HIGH); | |
digitalWrite(S3, LOW); | |
return pulseIn(sensorOut, LOW); ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment