Advertisement
Guest User

Servo e Button

a guest
Dec 26th, 2015
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #include <Servo.h>
  2.  
  3. Servo myservo;
  4.  
  5. int posicao = 0;
  6.  
  7. void setup()
  8. {
  9.   myservo.attach(5);
  10.   myservo.write(posicao);
  11. }
  12.  
  13. void loop()
  14. {
  15.   int botao_direita = digitalRead(8);
  16.   int botao_esquerda = digitalRead(9);
  17.  
  18.   if(botao_direita == HIGH && posicao <= 178)
  19.   {
  20.     posicao++;
  21.     myservo.write(posicao);
  22.   }
  23.  
  24.   if(botao_esquerda == HIGH && posicao >= 0)
  25.   {
  26.     posicao--;
  27.     myservo.write(posicao);
  28.   }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement