Advertisement
Guest User

Untitled

a guest
Feb 25th, 2025
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. // an array of the LED pin numbers
  2. // change this to match your LED pins
  3. int led_pins[] = {7, 6, 5};
  4.  
  5. void setup()
  6. {
  7. Serial.begin(115200);
  8. delay(2500); // ensure Serial is ready
  9. Serial.println("READY");
  10.  
  11. // if you have an array of LED pins you can use
  12. // it to set all LED pin modes as OUTPUT
  13. for (int i=0; i < 3; ++i)
  14. {
  15. pinMode(led_pins[i], OUTPUT);
  16. }
  17. }
  18.  
  19. void loop()
  20. {
  21. // you would normally do this on the button push
  22. int result = millis() % 3;
  23. Serial.print(result); // DEBUG print
  24.  
  25. // turn off any LED that might be on and show
  26. // the newly selected LED
  27. for (int i=0; i < 3; ++i)
  28. {
  29. digitalWrite(led_pins[i], LOW);
  30. }
  31. digitalWrite(led_pins[result], HIGH);
  32. Serial.print(", turn on LED at pin ");
  33. Serial.println(led_pins[result]);
  34.  
  35. delay(500);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement