Advertisement
RuiViana

Controle de motor com millis()

Dec 15th, 2015
443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #define IN1 4
  2. #define IN2 5
  3. unsigned int MyDly1 = 1000;
  4. unsigned int Tempo1 = 0;
  5. unsigned int MyDly2 = 1000;
  6. unsigned int Tempo2 = 0;
  7. void setup()
  8. {
  9. }
  10.  
  11. void navegarAvanteNavio01 ()
  12. {
  13. //Gira o Motor A no sentido horario ( A vante)
  14. //Incluir na função NavegarAvanteNavio01()
  15.  
  16. if ((millis() - Tempo1) >= MyDly1) // Se Tempo1 for maior que MyDly1
  17. { // faça
  18. Tempo1 = millis(); // Recarrega o valor de millis() em Tempo1
  19. digitalWrite(IN1, HIGH);
  20. digitalWrite(IN2, LOW);
  21. }
  22.  
  23. //Para o motor A
  24. if ((millis() - Tempo2) >= MyDly2) // Se Tempo1 for maior que MyDly1
  25. { // faça
  26. Tempo2 = millis(); // Recarrega o valor de millis() em Tempo2
  27. digitalWrite(IN1, HIGH);
  28. digitalWrite(IN2, HIGH);
  29. }
  30. }
  31. void loop()
  32. {
  33. navegarAvanteNavio01 ();
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement