SHARE
TWEET

Untitled

a guest Jun 19th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Servo.h>
  2. //Next, we create an object of the servo library
  3.  
  4. Servo servo;
  5. //Next, we move proceed to the void setup function where we attach the servo object to a digital pin and set the servo angle to 0. This is known as centering the servo.
  6.  
  7. int angle = 0;
  8. boolean izquierda=LOW;
  9. int pinpulsa = 7;
  10. int pinservo = 13
  11. void setup() {
  12.   Serial.begin(115200);
  13.   servo.attach(pinservo);
  14.   servo.write(angle);
  15.   pinMode(pinpulsa,INPUT);
  16. }
  17. //Next, is the loop function. To turn make the servo rotate to a particular degree, we use the servo.write() function to write the degree of rotation we desire to the servo. We used the function to turn the servo from one to the other and back.
  18.  
  19. void loop()
  20. {
  21.   izquierda = (digitalRead(pinpulsa) == HIGH);
  22.   if (izquierda){
  23.  // scan from 0 to 180 degrees
  24.   for(angle = 0; angle < 180; angle++)  
  25.   {                                  
  26.     servo.write(angle);              
  27.     delay(15);                  
  28.   }
  29.  
  30.   }
  31.   else {
  32.  
  33.   // now scan back from 180 to 0 degrees
  34.   for(angle = 180; angle > 0; angle--)    
  35.   {                                
  36.     servo.write(angle);          
  37.     delay(15);      
  38.   }
  39.  
  40.   }
  41. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top