Hi,
I'm trying to create a code that turns an LED on when certain RGB values are read by the sensor. My starting code is below does anyone know how I can add to it to illuminate the LED when the RGB value is 000.
// Include I2C Library
#include <Wire.h>
// Include Sparkfun ISL29125 Library
#include <SparkFunISL29125.h>
// Declare sensor object
SFE_ISL29125 RGB_sensor;
// Calibration values
unsigned int redlow = 197;
unsigned int redhigh = 8103;
unsigned int greenlow = 158;
unsigned int greenhigh = 10195;
unsigned int bluelow = 162;
unsigned int bluehigh = 8807;
// Declare RGB Values
int redVal = 0;
int greenVal = 0;
int blueVal = 0;
void setup()
{
// Initialize serial communication
Serial.begin(9600);
// Initialize the ISL29125 with simple configuration so it starts sampling
if (RGB_sensor.init())
{
Serial.println("Sensor Initialization Successful\n\r");
}
}
void loop()
{
// Read sensor values (16 bit integers)
unsigned int red = RGB_sensor.readRed();
unsigned int green = RGB_sensor.readGreen();
unsigned int blue = RGB_sensor.readBlue();
// Convert to RGB values
int redV = map(red, redlow, redhigh, 0, 255);
int greenV = map(green, greenlow, greenhigh, 0, 255);
int blueV = map(blue, bluelow, bluehigh, 0, 255);
// Constrain to values of 0-255
redVal = constrain(redV, 0, 255);
greenVal = constrain(greenV, 0, 255);
blueVal = constrain(blueV, 0, 255);
Serial.print("Red: ");
Serial.print(redVal);
Serial.print(" - Green: ");
Serial.print(greenVal);
Serial.print(" - Blue: ");
Serial.println(blueVal);
// Delay for sensor to stabilize
delay(2000);