I AM A NEWBIE AND LOOKING FOR SOME ADVISE PLEASE
Looking to have a circle of 25 LEDs. They need to flash on/off one at a time, on after another starting with a push of a button
When the button is released lights need carry on flashing on/off for a short delay say (2 seconds) and then at the end of this time period one light is randomly selected to stay on until the button is pressed again
I have got the button working and light flashing in sequence
I am really struggling to get right information for the off delay and the random light to selection
My current code
//LED Pin Variables
int ledPins[] = {22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46}; //An array to hold the pin each LED is connected to
int buttonPin = 11; // button pin variable, we will be using pin 11
int val = 0; // variable to read button pin value
void setup()
{
//Set each pin connected to an LED to output mode (pulling high (on) or low (off)
for(int i = 0; i < 25; i++){ //this is a loop and will repeat 25 times
pinMode(ledPins[i],OUTPUT); //we use this to set each LED pin to output
} //the code this replaces is below
pinMode(buttonPin, INPUT_PULLUP); // set button pin to be an input
}
void loop( ) // run over and over again
{
val = digitalRead(buttonPin);
if(val == LOW)
oneOnAtATime();
}
//oneOnAtATime() - Will light one LED then the next turning off all the others
void oneOnAtATime(){
int delayTime = 100; //the time (in milliseconds) to pause between LEDs
//make smaller for quicker switching and larger for slower
for(int i = 0; i <= 25; i++){
int offLED = i - 1;
if(i == 0) {
offLED = 25 ;
}
digitalWrite(ledPins[i], HIGH); //turn on LED #i
digitalWrite(ledPins[offLED], LOW); //turn off the LED we turned on last time
delay(delayTime);
}
}
(thanks to Mitesh Upda for assistance so far)
Not sure if the above is best approach, but started with an array for the 25 pins thought this would save coding later.
can anyone help with this next stage or tell me if I have the wrong approach