Created
January 20, 2015 19:19
-
-
Save drifterz28/671381f2f097405015a2 to your computer and use it in GitHub Desktop.
servo code found on g+
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment