stickyBUG Code

The following sample code requires the lightBUG library.

Source Code


// import libraries...
#include <Wire.h>
#include "lightBUG.h"

// create light sensor object...
lightBUG bug = lightBUG();

// program initialisation...
void setup(void) 
{
   Serial.begin(9600);
   bug.begin();

   // set to fixed gain - auto not recommended when using interrupts...
   bug.setGain(TSL2561_GAIN_1X);                           // No gain ... use in bright light to avoid sensor saturation 
   bug.setIntegrationTime(TSL2561_INTEGRATIONTIME_402MS);  // 16-bit data but slowest conversions 
   bug.setInterruptControl();                              // level interrupt, any value outside of threshold range
   bug.setInterruptThreshold(1000, 0xFFFF);                // trigger on low level light
}

// main program entry point...
void loop(void) 
{  
  // light event triggered when light levels fall below threshold...
  if (bug.isLightEvent()) {
    Serial.print(bug.getLight()); Serial.println(" lux"); 
  }
}