Hi,
I try to turn on max 5 leds by pressing 2 buttons.
For this I used this script below.
But, after reset, the most time the same led is beaming.
Is there any improvement on it?
Gr.
Johan
int led[] = {3,4,5,6,7,8};
int numberLeds = 6;
int button1 = 9;
int button2 = 10;
void setup() {
for (i=0;i<5;i++){
pinMode(led[i],OUTPUT);
digitalWrite(led[i],LOW);
}
pinMode(button1,INPUT);
pinMode(button2,INPUT);
}
void loop() {
randomSeed(analogRead(0));
if (digitalRead(button1)&&digitalRead(button2)){
if(random(100)>50){
digitalWrite(led[random(numberLeds)],HIGH);
}
if(random(100)>50){
digitalWrite(led[random(numberLeds)],HIGH);
}
if(random(100)>50){
digitalWrite(led[random(numberLeds)],HIGH);
}
if(random(100)>50){
digitalWrite(led[random(numberLeds)],HIGH);
}
if(random(100)>50){
digitalWrite(led[random(numberLeds)],HIGH);
}
while(true){
delay(1000);
}
}
}