Created
April 28, 2016 20:20
-
-
Save nataliefreed/cb69cb16381ec69e81818ffabb0a7786 to your computer and use it in GitHub Desktop.
This file contains 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 <Servo.h> | |
//TODO: Change these variable names to the correct notes | |
Servo a; | |
Servo b; | |
Servo c; | |
Servo d; | |
Servo e; | |
Servo f; | |
Servo g; | |
Servo a2; | |
void setup() | |
{ | |
a.attach(2); //connects servo on pin 2 to Servo object in your code | |
b.attach(3); | |
c.attach(4); | |
d.attach(5); | |
e.attach(10); | |
f.attach(11); | |
g.attach(12); | |
a2.attach(13); | |
} | |
void loop() | |
{ | |
goForward(a); | |
goBack(a); | |
goForward(b); | |
goBack(b); | |
} | |
void goForward(Servo s) { | |
for(int pos=0;pos<=90;pos++) //counts UP from 0 degrees to 90 degrees | |
{ | |
s.write(pos); //tell servo to go to current position | |
delay(15); //give it a moment to get there. Control speed here! | |
} | |
} | |
void goBack(Servo s) { | |
for(int pos=90;pos<=0;pos--) //counts DOWN from 90 degrees to 0 degrees | |
{ | |
s.write(pos); //tell servo to go to current position | |
delay(30); //give it a moment to get there. Control speed here! | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment