stickyBUG Code

The following sample code requires the servoBUG library.

Source Code

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

// servo bug object...
servoBUG bug = servoBUG();

// program setup...
void setup() {
   // initialise servo bug and set resolution to 8 (1us) - this gives
   // a sweep range of 1000..2000, with 1500 being the centre point
   bug.begin(SERVO_BUG_ADDRESS);
   bug.setResolution(8); 

   // set both servos to start position as fast as they can go...
   bug.setSpeed(0,0);
   bug.setSpeed(1,0);
   bug.setPosition(0,1000);
   bug.setPosition(1,1000);

   // wait, then set new speeds
   delay(500);
   bug.setSpeed(0,20);   // full sweep about 4 seconds
   bug.setSpeed(1,80);   // full sweep about 1 seconds
}

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

   // sweep to maximum range...
   bug.setPosition(0,2000);
   bug.setPosition(1,2000);
   delay(4000); 

   // sweep to minimum range...
   bug.setPosition(0,1000); 
   bug.setPosition(1,1000); 
   delay(4000);
}