Random LED Flasher

The random( ) function generates pseudo-random numbers ranging from to 0 to 9. For random values of ‘i’, the corresponding LEDs in the array ON and OFF with a time delay of 50ms. This creates a random flashing of LEDs.

 The visual effect can be varied with the rate of LED transition, this can be adjusted by changing the time delay.



int i;
int ledarray[] = {2, 3, 4, 5, 6, 8, 9, 10, 11};
void setup()
 for (i = 0; i < 9; i++)
   pinMode (ledarray[i], OUTPUT);
void loop() {
 i = random(9);
 digitalWrite (ledarray[i], HIGH);
 digitalWrite (ledarray[i], LOW);
1 Star2 Stars3 Stars4 Stars5 Stars Rate Us!

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *