Advertisement
RuiViana

Exemplo de micros()

Apr 8th, 2016
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1.  
  2. long xpto = 0;
  3. long macaco = 0;
  4. long Ton = 750; // 10 a 750
  5. long Toff = 120; // 10 a 120
  6. byte Ligado = 0;
  7. //----------------------------------------
  8. void setup()
  9. {
  10. Serial.begin(9600);
  11. pinMode(13,OUTPUT);
  12. }
  13. //----------------------------------------
  14. void loop()
  15. {
  16. while (Ligado == 1)
  17. {
  18.  
  19. if ((micros() - xpto) >Ton)
  20. {
  21. digitalWrite(13,HIGH);
  22. //Serial.println((micros() - xpto));
  23. Ligado = 0;
  24. macaco = micros();
  25. }
  26. }
  27. while (Ligado == 0)
  28. {
  29. if ((micros() - macaco) >Toff)
  30. {
  31. digitalWrite(13,LOW);
  32. //Serial.println((micros() - macaco));
  33. Ligado = 1;
  34. xpto = micros();
  35. }
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement