SEN-12829

//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
Extra Resource
s
Processor Interrupts with Arduino
Installing an Arduino Library
Using the Logic Level Converter Board
Serial Communication via I2C Protocol
Using Github
Page 8 of 8
10
/
8
/
201
5
htt
p
s://learn.s
p
arkfun.com/tutorials/isl2912
5
-r
gb
-li
ht-senso
r
-hooku
p
-
g
uide?
_g
a=1.2396
2
...

SEN-12829

Mfr. #:
Manufacturer:
SparkFun
Description:
Optical Sensor Development Tools RGB Light Sensor - ISL29125
Lifecycle:
New from this manufacturer.
Delivery:
DHL FedEx Ups TNT EMS
Payment:
T/T Paypal Visa MoneyGram Western Union

Products related to this Datasheet