Same project different approach, I have to redo the whac a LED project

void setup(){
  Serial.begin(115200);
pinMode(11, OUTPUT);
pinMode(9, OUTPUT);
pinMode(6, OUTPUT);
pinMode(3, OUTPUT);
pinMode(12, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);

}
void loop(){
  int j,S0,S1,S2,S3,dec;
int sensorVal = digitalRead(2);
int x=0;
int y=1;
randomSeed( analogRead(0) + analogRead(1) + analogRead(2) + analogRead(3) + analogRead(4) + analogRead(5) );
j=random(0,4);
Serial.print("Number:");Serial.println(j);
delay(3000);

  S0= analogRead(12);
  S1= analogRead(8);
  S2= analogRead(7);
  S3= analogRead(4);
  
while ((S0 ==LOW)&&(S1 ==LOW)&&(S2 ==LOW)&&(S3 ==LOW));{
 if(j==0);
    S0= digitalRead(12);
  digitalWrite(11, HIGH);
if( S0 == LOW)
  digitalWrite(11, LOW);
}
while ((S0 ==LOW)&&(S1 ==LOW)&&(S2 ==LOW)&&(S3 ==LOW));{
  if(j==1);
    S1= digitalRead(8);
  digitalWrite(9, HIGH);
 if( S1 == LOW)
  digitalWrite(9, LOW);
}
while ((S0 ==LOW)&&(S1 ==LOW)&&(S2 ==LOW)&&(S3 ==LOW));{
if(j==2);
    S2= digitalRead(7);
  digitalWrite(6, HIGH);
 if( S2 == LOW)
  digitalWrite(6, LOW);
}
while ((S0 ==LOW)&&(S1 ==LOW)&&(S2 ==LOW)&&(S3 ==LOW));{
  if(j==3);
    S3= digitalRead(4);
  digitalWrite(3, HIGH);
 if( S3 == LOW)
  digitalWrite(3, LOW);
}
}

I do want to apologize from the old post. And im here again because the old file had to be redone differently. Currently have the arduino connected to a edushiled with this code i have to play whac a mole.
Problem is that all four light light up and even after i press a button they all re light up, any suggestions?

Apologize in advance if I dont respond on time im either at work or doing other assignments.

Which Arduino board are you using ?

ARDUINO R3

sortabler:
ARDUINO R3

UNO R3, or Mega R3?

uno r3

The semicolon is killing you:
while ((S0 ==LOW)&&(S1 ==LOW)&&(S2 ==LOW)&&(S3 ==LOW));unless your logic is extremely devious...

sortabler:
uno r3

  S0= analogRead(12);
  S1= analogRead(8);
  S2= analogRead(7);

??

S0 S1 S3 are push buttons in the edushield and on the while function it shows no errors when i upload it the the board

You are using a Uno
Pins 12, 8 and 7 on a Uno are digital pins
Why are you reading their state with analogRead() ?

the arduino is connected to a edushield and those pins got to a push button

the arduino is connected to a edushield

Maybe you need to explain what an "edushield" is, and how it changes the function of an Arduino digital pin to analog?

Analog inputs on an Uno are A0 to A5, also known as 14 to 19, but not 7, 8 or 12.

Just as an aside. I’m no statistician, so I’d be interested to hear if adding a bunch of (hopefully) random atmospheric reads is statistically more random that just using any one of them.

randomSeed( analogRead(0) + analogRead(1) + analogRead(2) + analogRead(3) + analogRead(4) + analogRead(5) );

randomseed helps truly randomize numbers for j
The edushield connect to the arduino and it has extra features like a mini speaker and LEDs ect.

download.jpg

The edushield connect to the arduino and it has extra features like a mini speaker and LEDs ect.

But I bet it doesn't make pins 7, 8 and 9 analog?

BTW, I just did a quick test of analogRead(on those pins 7, 8 and 12) with a button to ground and input_pullup, got values that hovered around 300 or so regardless of the button. I wonder what it's actually reading, if anything?

randomseed helps truly randomize numbers for j

I know what it does: I'm questioning whether or not adding random analogRead()s is actually statistically more random than just using one.

OP's pic:

download.jpg

pinMode(12, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP); 
pinMode(4, INPUT_PULLUP);

are the 4 black buttons in the middle and the outputs are tiny leds next to those buttons. And witht the randomseed i mean honestly i dont think my proffesor cares how random it gets just enough to play the game.

I did say my question about how random it is was an "aside" not part of your mainstream thread....

But the two things you need to look at (maybe more?) are that your analogRead()s of digital pins are not giving you the high (unpressed) and low (pressed) that you expect, and someone pointed out a ; on the end of your while statement.

Anyway, what's the code supposed to do?

the entire code is suppose to play whac a mole but with those 4 buttons.
the random number is going to allow one of the leds to light up and I have to push the button to turn it off. And after the random number turns the next led but this code turns all 4 leds on even with the random numbers.

After the ; correction

After the ; correction

You should probably post the code after each change, so readers know exactly the current state of play.

How to inline an image