Created
September 4, 2015 13:32
-
-
Save ringodin/da740afcdc4b90ffec6e 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> | |
Servo lefty; // create servo object to control a servo | |
Servo righty; // a maximum of eight servo objects can be created | |
int pos = 0; // variable to store the servo position | |
int leftEye = 13; | |
int rightEye = 12; | |
void setup() | |
{ | |
lefty.attach(9); // attaches the servo on pin 9 to the servo object | |
righty.attach(7); | |
pinMode(leftEye, OUTPUT); | |
pinMode(rightEye, OUTPUT); | |
} | |
void loop() | |
{ | |
/* //The code immediately below is not active, but could be if you want it to be. | |
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees | |
{ // in steps of 1 degree | |
lefty.write(pos); // tell servo to go to position in variable 'pos' | |
delay(15); // waits 15ms for the servo to reach the position | |
} | |
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees | |
{ | |
lefty.write(pos); // tell servo to go to position in variable 'pos' | |
delay(15); // waits 15ms for the servo to reach the position | |
} | |
*/ | |
lefty.write(0); //send left arm to 0 position | |
righty.write(0); //send right arm to 0 position | |
digitalWrite(leftEye, HIGH); //turn left eye on | |
digitalWrite(rightEye, HIGH); //turn right eye on | |
delay(500); // keep all of the above stuff happening for 500 milliseconds | |
lefty.write(180); //send left arm to 180 position | |
righty.write(180); //send right arm to 180 position | |
digitalWrite(leftEye, LOW); //turn left eye off | |
digitalWrite(rightEye, LOW); //turn right eye off | |
delay(500); // keep all of the above stuff happening for 500 milliseconds | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment