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

   // You can also manually set the gain or enable auto-gain support 
   // bug.setGain(TSL2561_GAIN_1X);      // No gain ... use in bright light to avoid sensor saturation 
   // bug.setGain(TSL2561_GAIN_16X);     // 16x gain ... use in low light to boost sensitivity 
   bug.enableAutoRange(true);         // Auto-gain ... switches automatically between 1x and 16x (watch if using ISR thresholds)
   bug.setIntegrationTime(TSL2561_INTEGRATIONTIME_402MS);  // 16-bit data but slowest conversions 
}

// main program entry point...
void loop(void) 
{  
   Serial.print(bug.getLight()); Serial.println(" lux");  
   delay(1000);
}