//Continuouslycheckifaninterruptoccured
//Ifso,printoutinterrupt#,sensorreadingforredligh
t,andtimesincelastinterrupttoserialmonitor
void loop()
{
static unsigned int lasti=0;//Storesthenumberofthel
astinterrupt
static unsigned long ms= millis();//Usedtocalculateth
etimebetweeninterrupts
uint16_tred_value=0;//St
oressensorreadingforredlig
htintensity
uint8_tflags=0;//Storesstatusflagsreadfromthesens
or
//Checkifaninterrupthasoccured,ifso,entertheifbl
ock
if (lasti!= i)
{
//Readthedetectedlightintensityoftheredvisiblesp
ectrum
red_value= RGB_sensor.readRed();
//Printouttheinterrupt#andsensorreading
S
erial.print("Interrupt#:");
Serial.println(i);
Serial.print("RedSensorValue(HEX):");
Serial.println(red_value,HEX);
//Printoutthe#ofmillisecondssincethelastinterrup
t
Serial.print("Millisecondssincelastinterrupt:");
Serial.println(millis() ms);
Serial.println();
ms= millis();//Resetmssowecanstartcountingmillis
econdsuptothenextinterrupt
//Setlastitoi,sothatthisifstatementisnote
ntere
dagainuntilanotherinterruptistriggered
lasti=i;
//Readandclearthestatusflagsincludingtheinterrup
ttriggeredflag
//Thismustbedoneotherwiseanotherinterruptfromthe
sensorcannotbetriggered
flags=
RGB_sensor.readStatus();
//Ifyoudesiretoseethereportedstatusofthechip,u
ncommentthelinebelow
//checkSensorStatus(flags);
}
}
Interrupts are quite useful when you want to monitor for a change in light
level but don’t know when it might happen. Remember to modify the
configuration registers and the interrupt thresholds to what’s suitable for
your application.
Resources and Going Further
By now you’ve become familiar with the the ISL29125 sensor, the breakout
board hardware, how to acquire sensor readings, and how to implement
advanced configurations and interrupts. Enjoy experimenting and seeing
what creative uses you find for this sensor. Always feel free to share your
projects and/or feedback with us here at SparkFun!
Page 7 of 8