stickyBUG Code

The following sample code requires the expanderBUG library.

Source Code

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

 // expanderBUG object
expanderBUG bug = expanderBUG();

// program setup...
byte outputVar = 1;
void setup() {
   bug.begin(EXP_BUG_ADDRESS);  // set bug address
   bug.setConfig(B00000000);    // set all pins to output
}

// main program loop - assumes 8 Leds are attached to expander output - program
// will set Leds high in following sequence
// 0000 0001
// 0000 0010
// 0000 0100 and so on...
void loop() {
   bug.setOutput(outputVar);                      // set expander(0) to high
   outputVar = outputVar << 1;                    // shift to next expander pin
   if (outputVar == 0) outputVar = 1;             // if all pins serviced, reset... 
   delay(250);                                    // wait
}