/*
* Blink pin13 LED randomly 1 to 7 times, with longer random-length pauses between the blink-sequences
*
*/
long randPause = 0; // Initialize a variable for a short Pause time between subsequent blinks
long randOff = 0; // Initialize a variable for the OFF time between blink sequences
int randNumber;
void setup() // run once, when the sketch starts
{
pinMode(13, OUTPUT); // sets the digital pin as output
randomSeed (analogRead (0)); // read from an analog port with nothing connected
}
void loop() // run over and over again
{
randPause = random (200, 1000); // generate Pause time between 0,2 and 1 seconds (time between blinks in a sequence)
randOff = random (5000, 1000); // generate OFF time between 5 and 10 seconds (time between sequences)
randNumber = random(8); //
if (randNumber==1) // blink once if random number is 1
{
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for one second while LED is ON
digitalWrite(13, LOW); // sets the LED off
delay(randOff); // waits for a random time while LED is OFF
}
else if (randNumber==2) // blink twice if random number is 2
{
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for one second while LED is ON
digitalWrite(13, LOW); // sets the LED off
delay(randPause); // Pause time between 0,2 and 1 seconds
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for one second while LED is ON
digitalWrite(13, LOW); // sets the LED off
delay(randOff); // waits for a random time while LED is OFF
}
else if (randNumber==3) // blink three times if random number is 3
{
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for one second while LED is ON
digitalWrite(13, LOW); // sets the LED off
delay(randPause); // Pause time between 0,2 and 1 seconds
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for one second while LED is ON
digitalWrite(13, LOW); // sets the LED off
delay(randPause); // Pause time between 0,2 and 1 seconds
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for one second while LED is ON
digitalWrite(13, LOW); // sets the LED off
delay(randOff); // waits for a random time while LED is OFF
}
else if (randNumber==4) // blink four times if random number is 4
{
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for one second while LED is ON
digitalWrite(13, LOW); // sets the LED off
delay(randPause); // Pause time between 0,2 and 1 seconds
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for one second while LED is ON
digitalWrite(13, LOW); // sets the LED off
delay(randPause); // Pause time between 0,2 and 1 seconds
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for one second while LED is ON
digitalWrite(13, LOW); // sets the LED off
delay(randPause); // Pause time between 0,2 and 1 seconds
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for one second while LED is ON
digitalWrite(13, LOW); // sets the LED off
delay(randOff); // waits for a random time while LED is OFF
}
else if (randNumber==5) // blink five times if random number is 5
{
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for one second while LED is ON
digitalWrite(13, LOW); // sets the LED off
delay(randPause); // Pause time between 0,2 and 1 seconds
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for one second while LED is ON
digitalWrite(13, LOW); // sets the LED off
delay(randPause); // Pause time between 0,2 and 1 seconds
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for one second while LED is ON
digitalWrite(13, LOW); // sets the LED off
delay(randPause); // Pause time between 0,2 and 1 seconds
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for one second while LED is ON
digitalWrite(13, LOW); // sets the LED off
delay(randPause); // Pause time between 0,2 and 1 seconds
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for one second while LED is ON
digitalWrite(13, LOW); // sets the LED off
delay(randOff); // waits for a random time while LED is OFF
}
else if (randNumber==6) // blink sx times if random number is 6
{
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for one second while LED is ON
digitalWrite(13, LOW); // sets the LED off
delay(randPause); // Pause time between 0,2 and 1 seconds
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for one second while LED is ON
digitalWrite(13, LOW); // sets the LED off
delay(randPause); // Pause time between 0,2 and 1 seconds
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for one second while LED is ON
digitalWrite(13, LOW); // sets the LED off
delay(randPause); // Pause time between 0,2 and 1 seconds
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for one second while LED is ON
digitalWrite(13, LOW); // sets the LED off
delay(randPause); // Pause time between 0,2 and 1 seconds
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for one second while LED is ON
digitalWrite(13, LOW); // sets the LED off
delay(randPause); // Pause time between 0,2 and 1 seconds
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for one second while LED is ON
digitalWrite(13, LOW); // sets the LED off
delay(randOff); // waits for a random time while LED is OFF
}
else if (randNumber==7) // blink seven times if random number is 7
{
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for one second while LED is ON
digitalWrite(13, LOW); // sets the LED off
delay(randPause); // Pause time between 0,2 and 1 seconds
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for one second while LED is ON
digitalWrite(13, LOW); // sets the LED off
delay(randPause); // Pause time between 0,2 and 1 seconds
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for one second while LED is ON
digitalWrite(13, LOW); // sets the LED off
delay(randPause); // Pause time between 0,2 and 1 seconds
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for one second while LED is ON
digitalWrite(13, LOW); // sets the LED off
delay(randPause); // Pause time between 0,2 and 1 seconds
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for one second while LED is ON
digitalWrite(13, LOW); // sets the LED off
delay(randPause); // Pause time between 0,2 and 1 seconds
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for one second while LED is ON
digitalWrite(13, LOW); // sets the LED off
delay(randPause); // Pause time between 0,2 and 1 seconds
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for one second while LED is ON
digitalWrite(13, LOW); // sets the LED off
delay(randOff); // waits for a random time while LED is OFF
}
}
Moderator edit: code tags added