stickyBUG Code

The following sample code requires the motorBUG library.

Source Code

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

// constants and variables...
const byte motorID = 1;           // motor id = can be 1 or 2
const byte freq = 0;              // motor pwm frequency id (0..4)
motorBUG bug = motorBUG();        // motor bug object
unsigned int motorSpeed = 0;      // motor speed 0..511

// program setup...
void setup() {
   bug.begin(MOTOR_BUG_ADDRESS);
   bug.setFreq(freq);
   bug.standbyOff(); 
   bug.turnCW(motorID);  
}

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

      // accelerate the motor...
      while (motorSpeed < 511) {
         bug.setSpeed(motorID, motorSpeed);  
         motorSpeed++;
         delay(10);
      } 

      // max speed set (511), no decelerate...
      while (motorSpeed > 0) {
         bug.setSpeed(motorID, motorSpeed); 
         motorSpeed--;
         delay(10);
      }
}