Advertisement
Jorge_moises

Untitled

Jan 2nd, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. // Rui
  2. // Seguencia LEDs usando o CI 74HC595
  3.  
  4. #define clock 2 // Conectar ao pino 11 dos 74HC595
  5. #define data 3 // Conectar ao pino 14 dos 74HC595
  6. #define latch 4 // Conectar ao pino 12 dos 74HC595
  7. #define botao 8 // Botão ligado no pino 8
  8. bool Level; // Nivel de Data
  9. bool estadoB = LOW; // Indicador se botão foi acionado
  10. byte Cnt = 0; // Contador de saidas
  11. // ********************************************************************
  12. void setup(){
  13. Serial.begin(9600);
  14. pinMode(clock,OUTPUT); // Port D2 saída
  15. pinMode(data,OUTPUT); // Port D3 saída
  16. pinMode(latch,OUTPUT); // Port D4 saída
  17. pinMode (botao, INPUT_PULLUP); // Botão para avancar
  18. Apaga(); // Apaga tudo antes de iniciar
  19. }
  20. //----------------------------------------------------------------------
  21. void HC595(){
  22. digitalWrite(data,Level); // Data bit ON acende 1o. LED
  23. digitalWrite(latch,LOW); // transfere dados dos regs para os latchs e saídas
  24. digitalWrite(clock,HIGH); // Liga clock para entra dado
  25. digitalWrite(clock,LOW); // Desiga clock
  26. digitalWrite(latch,HIGH); // Desatica transferencia
  27. }
  28. //---------------------------------------------------------------
  29. void Apaga (){ // Rotina para apagar tudo
  30. Level = 0; // Define nivel das saidas
  31. Cnt = 0; // Contador de saida
  32. for (unsigned int i = 0; i<8; i++){ // Faça 8 vezes
  33. HC595(); // Envia para o 595
  34. }
  35. }
  36. // ********************************************************************
  37. void loop(){
  38. while (digitalRead (botao) == HIGH){ // Se botão não está acionado
  39. estadoB = HIGH; // Diga que ele esta HIGH
  40. }
  41. while (digitalRead (botao) == LOW){ // Se botão está acionado
  42. if (estadoB == HIGH){ // Se ele foi acionado
  43. estadoB = LOW; //. Limpa a indicação
  44. Serial.println(Cnt);
  45. Cnt++; // Incrementa saida
  46. Level = 1; // inverta o nivel de Data
  47. HC595(); // Envia para o 595
  48. delay(100); // Tempo de 50 ms
  49. }
  50. }
  51. if (Cnt >8){ // Se a saida é maior que 8, apaga tudo
  52. Apaga();
  53. }
  54. } // End loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement