Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- Servo servo1; Servo servo2;
- #define servoPin A0 //analog pin 0
- #define servoPin2 A1 //analog pin 1
- void setup() {
- pinMode(servoPin,OUTPUT); // Set servoPin to be an output pin
- servo1.attach(servoPin); // Attach the servo
- pinMode(servoPin2,OUTPUT); // Set servoPin2 to be an output pin
- servo2.attach(servoPin2); // Attach a second servo
- Serial.begin(57600); //Set up the serial connection
- Serial.println("Ready"); //Prints to the serial monitor to let us know things are working
- }
- void loop() {
- static int v = 0;
- if ( Serial.available()) {
- char ch = Serial.read();
- switch(ch) {
- case '0'...'9':
- v = v * 10 + ch - '0';
- break;
- case 's':
- servo1.write(v);
- v = 0;
- break;
- case 'w':
- servo2.write(v);
- v = 0;
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement