ISL29125 RGB Light Sensor

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);

There is no LED in your code, which I assume is ISL29125_basics.ino from the github library examples. So guess you mean how to get that 000 condition reported by the print statement?

I don't have that sensor so can't experiment, but I'm curious how you will test that physical light combination in practice?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.