Advertisement
Guest User

twin servo (arduino)

a guest
Jun 15th, 2014
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <Servo.h>
  2.  
  3. Servo servo1; Servo servo2;
  4.  
  5. #define servoPin A0 //analog pin 0
  6. #define servoPin2 A1 //analog pin 1
  7. void setup() {
  8.  
  9.   pinMode(servoPin,OUTPUT); // Set servoPin to be an output pin
  10.   servo1.attach(servoPin);  // Attach the servo
  11.   pinMode(servoPin2,OUTPUT); // Set servoPin2 to be an output pin
  12.   servo2.attach(servoPin2); // Attach a second servo
  13.  
  14.   Serial.begin(57600); //Set up the serial connection
  15.   Serial.println("Ready"); //Prints to the serial monitor to let us know things are working
  16.  
  17. }
  18.  
  19. void loop() {
  20.  
  21.   static int v = 0;
  22.  
  23.   if ( Serial.available()) {
  24.     char ch = Serial.read();
  25.  
  26.     switch(ch) {
  27.       case '0'...'9':
  28.         v = v * 10 + ch - '0';
  29.         break;
  30.       case 's':
  31.         servo1.write(v);
  32.         v = 0;
  33.         break;
  34.       case 'w':
  35.         servo2.write(v);
  36.         v = 0;
  37.         break;
  38.     }
  39.   }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement