6
void loop()
{
int red, green, blue;
GroveColorSensor colorSensor;
colorSensor.ledStatus = 1; // When turn on the color sensor LED, ledStatus = 1; When
turn off the color sensor LED, ledStatus = 0.
while(1)
{
colorSensor.readRGB(&red, &green, &blue); //Read RGB values to variables.
delay(300);
Serial.print("The RGB value are: RGB( ");
Serial.print(red,DEC);
Serial.print(", ");
Serial.print(green,DEC);
Serial.print(", ");
Serial.print(blue,DEC);
Serial.println(" )");
colorSensor.clearInterrupt();
}
}
4.4 Color Sensor Examples/Applications
These example are going to show you how to use features of Grove - I2C Color Sensor. And via
Chainable RGB LED Grove to display the detected color.
Notice: If you haven't download Grove-Chainable RGB LED library to your Arduino IDE before,
please download and set up the library first.
Open File->Examples->Color_Sensor->example->ColorSensorWithRGB-LED sketch for a
complete example, or copy and paste code below to a newArduino sketch.
Description: This example can measure the color chromaticity of ambient light or the color of
objects, and via Chainable RGB LED Grove displaying the detected color.
You also can use other display module to display the detected color by Grove - I2C Color
Sensor.
#include <Wire.h>
#include <GroveColorSensor.h>
#include <ChainableLED.h>
#define CLK_PIN 7
#define DATA_PIN 8
#define NUM_LEDS 1 //The number of Chainable RGB LED