Advertisement
Guest User

Untitled

a guest
Mar 16th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Projeto 5 – Efeito de iluminação sequencial com LEDs
  2. byte ledPin[] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; // cria um array para os pinos dos LEDs
  3. int ledDelay(65); // intervalo entre as alterações
  4. int direction = 1;
  5. int currentLED = 0;
  6. unsigned long changeTime;
  7. void setup() {
  8. for (int x=0; x<10; x++) { // define todos os pinos como saída
  9. pinMode(ledPin[x], OUTPUT); }
  10. changeTime = millis();
  11. }
  12. void loop() {
  13. if ((millis() - changeTime) > ledDelay) { // verifica se já transcorreram ledDelay ms desde
  14. // a última alteração
  15. changeLED();
  16. changeTime = millis();
  17. }
  18. }
  19. void changeLED() {
  20. for (int x=0; x<10; x++) { // apaga todos os LEDs
  21.  digitalWrite(ledPin[x], LOW);
  22. }
  23. digitalWrite(ledPin[currentLED], HIGH); // acende o LED atual
  24. currentLED += direction; // incrementa de acordo com o valor de direction
  25. // altera a direção se tivermos atingido o fim
  26. if (currentLED == 9) {direction = -1;}
  27. if (currentLED == 0) {direction = 1;}
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement