Professional Documents
Culture Documents
const byte LED_PINS[] = {9, 10, 11}; // Pins of the LEDs in R, G, B order. IMPORTANT!
bool doCalibration = true; // Set "true" if you want to do calibration, "false" otherwise.
int whiteValue[] = {909, 947, 946}; // Change this value according to your calibration value.
int blackValue[] = {779, 820, 838}; // Change this value according to your calibration value.
// Tune this value in case you think the value of the channel is too high or too low
int colourValue[3]; // This variable will hold the currently scanned colour.
void setup() {
pinMode(LDR_PIN, INPUT); // Set the LDR that will be reading the colour value as input.
digitalWrite(LED_PINS[i], HIGH); // Write HIGH for common anode RGB LED. LOW if common cathode.
calibrateColourSensor();
}
void loop() {
void calibrateColourSensor() {
waitForInput(); // Wait for the user to press enter in the serial monitor
waitForInput(); // Wait for the user to press enter in the serial monitor
}
Serial.println("Calibration complete.");
waitForInput(); // Wait for the user to press enter in the serial monitor
void waitForInput() {
void checkColour() {
}
}
int total = 0;
void calculateColour() {
//This function prints the value colour in the following form: (RRR,GGG,BBB). Eg. (34,150,200)
void printColour() {
Serial.print("(");
Serial.print(colourValue[0]); //Red
Serial.print(",");
Serial.print(colourValue[1]); //Green
Serial.print(",");
Serial.print(colourValue[2]); //Blue
Serial.print(")\t");
// This part requires thinkering and depends heavily on the values that you get.
if (colourValue[0] < 200 && colourValue[1] < 120 && colourValue[2] > 100) {
Serial.println("BLUE");
else if (colourValue[0] > 200 && colourValue[1] < 200 && colourValue[2] < 150) {
Serial.println("RED");
else if (colourValue[0] > 200 && colourValue[1] > 200 && colourValue[2] < 200) {
Serial.println("YELLOW");
else {
Serial.println();