Advertisement
RuiViana

LED sequencial

Nov 7th, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. #include <ShiftOutMega.h> //Inclui a bilioteca ShiftOutMega.h
  2.  
  3. //Variáveis de uso dos registradores 74HC595
  4. int latchPin = 2; //Pino 8 conectado ao pino 12 do 74HC595 (Latch).
  5. int dataPin = 3; //Pino 11 conectado ao pino 14 do 74HC595 (Data).
  6. int clockPin = 4; //Pino 12 conectado ao pino 11 do 74HC595 (Clock).
  7.  
  8. //Quantidade de registradores (74HC595). Para cada registrador, temos 8 saídas.
  9. int qtdRegistradores = 1;
  10. byte LED = 0;
  11.  
  12.  
  13. ShiftOutMega mega(latchPin, dataPin, clockPin, qtdRegistradores); //Inicia a biblioteca passando os parametros de uso.
  14.  
  15. //---------------------------------
  16. int botao = 8;
  17. int estadoB;
  18.  
  19. void setup()
  20. {
  21. pinMode (botao, INPUT_PULLUP);
  22. }
  23.  
  24. void loop()
  25. {
  26. int totalSaidas = qtdRegistradores * 8; // Quantida a ser acendida e apagada no caso em 8 em 8
  27.  
  28. while (digitalRead (botao) == LOW) // Testa se botão está apertado
  29. { // Faça enquanto estiver
  30. delay(10); // Delay 10ms para evitar debouncing
  31. estadoB == LOW; // Define que botão foi apertado
  32. }
  33. if(estadoB == LOW) // Se botão foi apertado
  34. estadoB = HIGH; // Desliga a informação
  35. LED++; // Incrementa contado de acendimento de LED
  36. mega.shiftWrite(LED, HIGH); // Acende LED
  37. if (LED > 7) // Se LED > que o oitavo
  38. {
  39. LED = 0; // Zera contador
  40. for (int i = 1; i <= totalSaidas; i++) // Inica apagamento de LEDs
  41. {
  42. mega.shiftWrite(i, LOW); // Apaga LED
  43. delay (10); // Delay 10 ms
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement