Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //random basic coding Randomly blinks one of 8 LEDs
- /*Code by Gary Granai steamtraininfo.com .
- Complete documentation and live demonstration at https://steamtraininfo.com/arduino-projects/random-blink-led
- Complete arduino for model railroaders library at https://steamtraininfo.com/arduino-projects
- You may freely use and change this sketch as long as all the information above is included unchanged.
- */
- void setup() {
- /* This sets 8 leds on pins D2 to D9 to output
- */
- for (int i = 2; i <= 9; i++) {
- pinMode(i, OUTPUT); // sets pins to output
- }
- randomSeed(analogRead(A0)); /*sets the pin to create "static so the the initial LED to light is different
- eacg time through the loop */
- }
- //***************************************************
- void loop() {
- BlinkRandomly();
- }
- //**************************************************
- void BlinkRandomly() {
- int LightLED = random(2, 10); //randomly selects LED to light. Must use +1 over the last pin number
- //(ie: 9 + 1 = 10)
- int dlay = 250; // sets the blink rate in milliseconds
- digitalWrite(LightLED, HIGH);
- delay(dlay);
- digitalWrite(LightLED, LOW);
- delay(dlay);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement