drifterz28
1/20/2015 - 7:19 PM

servo code found on g+

servo code found on g+

#include <SoftwareServo.h>

SoftwareServo myServo0;  //create a servo object.
  
void setup() {
    myServo0.attach(0);    //attach the servo to pin 0 on Trinket
    myServo0.write(90);     // tell servo to go to position per quirk on arduino.cc
    delay(15);            // waits 15ms for the servo to reach the position
    SoftwareServo::refresh();
}

void loop()
{
    for(int pos = 20; pos < 160; pos++)  // goes from 20  to 160 degrees
    {                                   // in steps of 1 degree
        myServo0.write(pos);             // tell servo to go to position 
        delay(15);                      // waits 15ms for the servo to reach the position
        SoftwareServo::refresh();
    }

    for(int pos = 160; pos > 20; pos--)  // goes from 160 to 20 degrees
    {
        myServo0.write(pos);             // tell servo to go to position 
        delay(15);                      // waits 15ms for the servo to reach 
        SoftwareServo::refresh();
    }
}

void delay_refresh(unsigned int delaytime)
{  // not used above

   for(int x=0;x<delaytime;x=x+25){
      delay(25);
      SoftwareServo::refresh();
    }
}