stickyBUG Code

The following sample code requires the bargraphBUG library.

Source Code

// import libraries...
#include <Wire.h>
#include <bargraphBUG.h>

// duty cycle array...       
byte duty[10] = {0,0,0,0,0,0,0,0,0,0,};

 // bargraphBUG object
bargraphBUG bug = bargraphBUG();

// program setup...
void setup() {
   bug.begin(BAR_BUG_ADDRESS);
}

// increase the brightness for Led(index)
void goUp(byte index) {
   while (duty[index] < 128) { 
      duty[index] = duty[index] + 1;
      bug.setValue(index, duty[index]);
      delay(1);
   }
}

// decreases the brightness for Led(index)
void goDown(byte index) {
   while (duty[index] > 0) {  
      duty[index] = duty[index] - 1;
      bug.setValue(index,duty[index]);
      delay(5);
   }
}

// main program loop...
void loop() {

   // turn all Leds on...
   for(byte i = 0; i < 10; i++) {  
      goUp(i);
   } 

   // now turn them off...
   for(byte i = 0; i < 10; i++) {  
      goDown(i);
   } 
}