kartonman

Lightning Flash Controller

Apr 4th, 2022 (edited)
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. /*Flash controller for 3 LEDs used on Thunder And Lighting Control Board
  2. This sketch created and copywrite by Gary C. Granai https://www.facebook.com/gary.granai and is included in the
  3. Arduino For Model Railing Library at https://steamtraininfo.com/arduino-projects
  4. You are free to use this sketch and amend it for your own personal use as long as these credits remain intact. Using it in any manner or form for commercial purposes is prohibited.*/
  5.  
  6. #define toggle A0
  7. int val=0;
  8.  
  9. int randNumber;
  10. void setup() {
  11. pinMode(A0, INPUT);
  12. /* This sets 3 leds on pins D4 to D6 to output */
  13. for (int i = 4; i <= 7; i++) {
  14. pinMode(i, OUTPUT); // sets pins to output
  15. }
  16. randomSeed(analogRead(A7)); /*sets the pin to create "static so the the initial LED to light is different
  17. eacg time through the loop */
  18. }
  19.  
  20. //***************************************************
  21. void loop() {
  22. BlinkRandomly();
  23. }
  24.  
  25. //**************************************************
  26. void BlinkRandomly() {
  27. val=analogRead(toggle);
  28. if(val>750){
  29. randNumber= random(20, 30);
  30. int LightLED = random(4, 7); //randomly selects LED to light. Must use +1 over the last pin number
  31. //(ie: 6 + 1 = 7)
  32. int dlay = randNumber; // sets the blink rate in milliseconds
  33. digitalWrite(LightLED, HIGH);
  34. delay(dlay);
  35. digitalWrite(LightLED, LOW);
  36. delay(dlay);
  37. }
  38. }
  39.  
Add Comment
Please, Sign In to add comment