Is there a way to delay the speed of the random seed function without using delay()? I'm trying to make a whac a mole style game by turning off the LEDs by a specific button. But it turns out that I'm having unwanted output on the LEDs when I use the delay and the LEDs wont turn off when I press the button for the lit up LED. Any suggestions? Here's the code. Don't mind the Serials. I'm just using them in checking the pulse and score. I'll be removing them on my final output.
int pulse1 = 0; int pulse2 = 0;
void setup()
{
pinMode(2,INPUT); pinMode(3,INPUT); pinMode(4,INPUT); pinMode(5,INPUT);
pinMode(6,OUTPUT); pinMode(7,OUTPUT); pinMode(8,OUTPUT); pinMode(9,OUTPUT);
randomSeed(analogRead(0));
Serial.begin(9600);
}
void loop()
{
randNumber = random(4);
if (randNumber = 0)
{
int pulse1 = 0;
int pulse2 = 0;
digitalWrite(8,LOW);
digitalWrite(9,LOW);
if (pulse1 <= 0)
{
digitalWrite(6,HIGH);
}
if (pulse2 <= 0)
{
digitalWrite(7,HIGH);
}
if (digitalRead(2) == HIGH)
{
pulse1++;
score++;
}
if (digitalRead(3) == HIGH)
{
pulse2++;
score++;
}
}
if (randNumber = 1)
{
int pulse1 = 0;
int pulse2 = 0;
digitalWrite(6,LOW);
digitalWrite(7,LOW);
if (pulse1 <= 0)
{
digitalWrite(8,HIGH);
}
if (pulse2 <= 0)
{
digitalWrite(9,HIGH);
}
if (digitalRead(4) == HIGH)
{
pulse1++;
score++;
}
if (digitalRead(5) == HIGH)
{
pulse2++;
score++;
}
}
if (randNumber = 2)
{
int pulse1 = 0;
int pulse2 = 0;
digitalWrite(6,LOW);
digitalWrite(8,LOW);
if (pulse1 <= 0)
{
digitalWrite(9,HIGH);
}
if (pulse2 <= 0)
{
digitalWrite(7,HIGH);
}
if (digitalRead(5) == HIGH)
{
pulse1++;
score++;
}
if (digitalRead(3) == HIGH)
{
pulse2++;
score++;
}
}
if (randNumber = 3)
{
int pulse1 = 0;
int pulse2 = 0;
digitalWrite(7,LOW);
digitalWrite(9,LOW);
if (pulse1 <= 0)
{
digitalWrite(6,HIGH);
}
if (pulse2 <= 0)
{
digitalWrite(8,HIGH);
}
if (digitalRead(2) == HIGH)
{
pulse1++;
score++;
}
if (digitalRead(4) == HIGH)
{
pulse2++;
score++;
}
}
Serial.println(score);
Serial.println(pulse1);
Serial.println(pulse2);
delay(1000);
}