Simon game error: expected primary-expression before "}" token

Hello I am currently trying to code a game similar to simon for a school project. The error expected primary -expression before "}" token keeps coming up. I am new to this so any help would be appreciated. thanks:)

Simon_project.ino (1.86 KB)

On phone, so can't view .ino (use code tags and put it in the post!)

probably mismatched {}'s

Use ctrl+t to format code with indentation so you can easily see mistakes with {}'s

Sorry here is the code


const int LED1 = 1;
const int b1 = 3;
const int LED2 = 5;
const int b2 = 7;
const int LED3 = 9;
const int b3 = 11;

int numA[4];
int level;

void setup() {
// put your setup code here, to run once:
pinMode (LED1, OUTPUT);
pinMode (b1, INPUT);
pinMode (LED2, OUTPUT);
pinMode (b2, INPUT);
pinMode (LED3, OUTPUT);
pinMode (b3, INPUT);

digitalWrite (LED1, LOW);
digitalWrite (LED2, LOW);
digitalWrite (LED3, LOW); // all leds off
}

void loop() {
for (int i=0; i>9; i++)
{
randomSeed(millis());
numA = random(1, 4); // assigns led color to flash for each level

  • }*
    for (level=1; level<11; level ++)
    {
  • for (int i=0; i<level; i++)*
  • {*
    _ if (numA == 1) // if the random color lit up is 1, then the 1st light turns on_
    * {*
    * digitalWrite(LED1, HIGH);*
    * }*
    _ else if (numA == 2)
    * {
    digitalWrite(LED2, HIGH);
    }
    else (numA == 3);
    {
    digitalWrite(LED3, HIGH);
    }
    }
    }
    delay (500);
    for (level=1; level<11; level ++)
    {
    do{
    digitalRead(b1);
    digitalRead(b2);
    digitalRead(b3);
    }
    while(b1 == HIGH && b2 == HIGH && b3 == HIGH);
    {
    if (b1 == LOW) // checks button presses to be correct*

    * if (b2 == LOW)
    if (b3 == LOW)
    } else {BP!= numA{
    for (int i=0; i<level; i++){ lose sequence*

    * digitalWrite(LED1, HIGH);
    delay(1000);
    digitalWrite(LED1, LOW);
    digitalWrite(LED2, HIGH);
    delay(1000);
    digitalWrite(LED2, LOW);
    digitalWrite(LED3, HIGH);
    delay(1000;
    digitalWrite(LED3, LOW);
    }
    }
    }
    }
    Do{ win sequence
    digitalWrite(LED1, HIGH);
    delay(2000);
    digitalWrite(LED1, LOW);
    digitalWrite(LED2, HIGH);
    delay(2000);
    digitalWrite(LED2, LOW);
    digitalWrite(LED3, HIGH);
    delay(2000;
    digitalWrite(LED3, LOW);
    }while{
    level = 11;
    }
    }*_

Say wwwhat?
if (b1 == LOW) // checks button presses to be correct
if (b2 == LOW)
if (b3 == LOW)


???
else (numA == 3);

else {BP!= numA{


for (int i=0; i<level; i++){ lose sequence

. . .

Do{ win sequence

Comments need

//


delay(1000;


Do <———<<<< do

Time to say stop and learn the basics.

There are lots of errors in your program. :frowning:
Use the reference pages for examples how each function etc is used:

Some quick notes:
An array numA[4] is declared but never used. A variable numA is used but never formally declared.

I am not sure what this bit of code is supposed to do.
for (int i=0; i>9; i++){
randomSeed(millis());
numA = random(1, 4); // assigns led color to flash for each level
}

I see this as setting i to 0, doing the for-loop in which a single variable "numA" is set to a random value, then incrementing i (now i is 1), checking if i is greater than 9, it isn't so it would exit the for-loop. The for-loop is only ever executed once per Main Loop execution. See correction by TheMemberFormerlyKnownAsAWOL in following post. I'm an idiot!

Edit: I see this as setting i to 0,checking if i is greater than 9, it isn't so it would exit the for-loop. The for-loop is never executed each Main Loop execution.

Did you want to assign a random value to each of the 4 array variables?
If so this could read:

for (int X=0; X<4; X++)
{
randomSeed(millis());
numA[X]= random(1, 4); // assigns led color to flash for each level
}
Note: used X instead of i as the post editor keeps interpreting the [i as italics.

For a single value of numA no loop is required:

randomSeed(millis());
numA = random(1, 4); // assigns led color to flash for each level

Another problem area:
do{
digitalRead(b1);
digitalRead(b2);
digitalRead(b3);
}
while(b1 == HIGH && b2 == HIGH && b3 == HIGH);

This would do nothing.
Note b1,b2,b3 were declared as constants not variables.

The results of a call to digitalread( ) needs to be stored in a variable if you want to use it later so a statement such as
statusB1 = digitalRead(b1); will store the result in statusB1 then statusB1 can be used to check what to do.
You could use something like
while(digitalRead(b1) == HIGH && digitalRead(b2) == HIGH && digitalRead(b3) == HIGH);
if you didn't need to refer to the input values later. (Wise to use input pullup on inputs if available on the micro).

if (b1 == LOW) // checks button presses to be correct
if (b2 == LOW)
if (b3 == LOW)
Makes no sense, not sure what is being done here. Where are the "{ }" for each if? Are the checks meant to be nested ifs or a single check that all three are low or if just one is low?

cjones7:
.

I am not sure what this bit of code is supposed to do.
for (int i=0; i>9; i++){
randomSeed(millis());
numA = random(1, 4); // assigns led color to flash for each level
}

I see this as setting i to 0, doing the for-loop in which a single variable "numA" is set to a random value, then incrementing i (now i is 1), checking if i is greater than 9, it isn't so it would exit the for-loop. The for-loop is only ever executed once per Main Loop execution.

Correction: the body of the for loop is NEVER executed.