Created
July 27, 2012 02:29
-
-
Save sarcilav/3185870 to your computer and use it in GitHub Desktop.
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 <Servo.h> | |
| Servo myservo; // create servo object to control a servo | |
| // a maximum of eight servo objects can be created | |
| int pos = 0; // variable to store the servo position | |
| int incomingByte = 0; // for incoming serial data | |
| void setup() | |
| { | |
| Serial.begin(9600); | |
| myservo.attach(9); // attaches the servo on pin 9 to the servo object | |
| myservo.write(pos); | |
| } | |
| void loop() | |
| { | |
| if(Serial.available() > 0) | |
| { | |
| // read the incoming byte: | |
| incomingByte = Serial.read(); | |
| if(incomingByte == 119) // 'w' | |
| pos += 45; | |
| else if(incomingByte == 115) // 's' | |
| pos -= 45; | |
| myservo.write(pos); | |
| delay(15); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment