whatColorIsIt?

whatColorIsIt?

Detect Color with Color Sensor

Using getColorSensor() we get a letter corresponding to the color of the object on the sensor. Possible colors are R (red), O (orange), Y (yellow), G (green), B (blue), or P (purple). Based on this return the program outputs the color to the computer using the serial port.

Commands Used

getSensorColor()

Serial.print(x)

Serial.println(x)

 

Cut and paste code:

#include <robotInputs.h>

void setup() {

  Serial.begin(9600);

  robotInputsActivate();  //Let Arduino know the commands and returns from Inputs are comming. This turns on the I2C bus
  colorSensorEnable();    //Tell the color sensor to wake up. By default the sensor is asleep

}

void loop() {
  char colorLetter = getSensorColor();  //returns a letter corosponding the the color detected (R,O,Y,G,B,P)
  if (colorLetter == 'R') {
    Serial.println("Detected Red");
  }
  else if (colorLetter == 'O') {
    Serial.println("Detected Orange");
  }
  else if (colorLetter == 'Y') {
    Serial.println("Detected Yellow");
  }
  else if (colorLetter == 'G') {
    Serial.println("Detected Green");
  }
  else if (colorLetter == 'B') {
    Serial.println("Detected Blue");
  }
  else if (colorLetter == 'P') {
    Serial.println("Detected Purple");
  }
  else Serial.println("No Color Detected");
  delay(100);

}