KingOfWesteros

Aula 04 - Servomotor

Apr 21st, 2021
741
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # ---Servomotor---
  2.  
  3. #include <Servo.h>
  4.  
  5. #define SERVO 13 // Porta digital 13
  6.  
  7. Servo s; // Variável Servo
  8. int pos; //Posição do Servomotor
  9.  
  10. void setup()
  11. {
  12.   s.attach(SERVO);
  13.   s.write(90); //Posição inicial do motor
  14. }
  15.  
  16. void loop()
  17. {
  18.   viraDireita();
  19.   delay(2000);
  20.   viraEsquerda();
  21.   delay(2000);
  22. }
  23.  
  24. void viraDireita() {
  25.   for(pos = 90; pos > 0; pos--) {
  26.     s.write(pos);
  27.     delay(15);
  28.   }
  29.   for(pos = 0; pos < 90; pos++) {
  30.     s.write(pos);
  31.     delay(15);
  32.   }
  33. }
  34.  
  35. void viraEsquerda() {
  36.   for(pos = 90; pos < 180; pos++) {
  37.     s.write(pos);
  38.     delay(15);
  39.   }
  40.   for(pos = 180; pos > 90; pos--) {
  41.     s.write(pos);
  42.     delay(15);
  43.   }
  44. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×