Advertisement
RuiViana

Pisca LED

Oct 17th, 2015
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. byte led = 3;
  2. int valor = 0; // Guarda o valor da batida
  3. int botao = 8;
  4. byte Indicador = 0;
  5. void setup()
  6. {
  7. pinMode (led, OUTPUT);
  8. pinMode (botao, INPUT);
  9. }
  10.  
  11. void loop()
  12. {
  13. valor = digitalRead (botao);
  14. if(valor == HIGH) // Verifica se o botao foi pressionado
  15. {
  16. delay(300); // Tempo para evitar debouncing
  17. if(valor == HIGH) // Confirma se o botao continua pressionado
  18. {
  19. if (Indicador == 1) // Testa se o bt foi apertado uma vez
  20. { // Se já foi, faça
  21. for (byte i = 0; i<4; i++) // Faça 3 vezes
  22. {
  23. digitalWrite(led, HIGH); // Atribui nível lógico alto ao pino do LED, acendendo-o
  24. delay(500); // Espera 500 milissegundos (1/2 segundo)
  25. digitalWrite(led, LOW); // Atribui nível lógico baixo ao pino do LED, apagando-o
  26. delay(3000); // Espera 3000 milissegundos (3 segundos)
  27. Indicador = 0; // Zera indicador de bt apertado uma vez
  28. }
  29. }
  30. else Indicador = 1; // Se não foi apertado uma vez, indica que é a primeira ve
  31. }
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement