Expected ';' before '{' token with additional problem

The error is: "expected ';' before '{' token" , and when I put ";", the error of the evolves into "expected primary-expression before '{' token". Please help I'm just a newbie.

Code:

#include <Wire.h>
#include <Keypad.h>
#include <Servo.h>
#include <EEPROM.h>
#include <LiquidCrystal_I2C.h>

int Led = 12;
int buzzer = 13;
int count = 0;

const byte numRows = 4;         //number of rows on the keypad
const byte numCols = 4;         //number of columns on the keypad

char keymap[numRows][numCols] =
{
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

char keypressed;                 //Where the keys are stored it changes very often
char code[] = {'1', '2', '3', '4'}; //The default code, you can change it or make it a 'n' digits one

char check1[sizeof(code)];  //Where the new key is stored
char check2[sizeof(code)];  //Where the new key is stored again so it's compared to the previous one

char pass[] = {'1', '1', '1','1'};

short a = 0,a2 = 0, i = 0, i2 = 0, s = 0, s2 = 0, j = 0, j2 = 0; //Variables used later

byte rowPins[numRows] = {2, 3, 4, 5}; //Rows 0 to 3 //if you modify your pins you should modify this too
byte colPins[numCols] = {6, 7, 8, 9}; //Columns 0 to 3

LiquidCrystal_I2C lcd(0x27, 16, 2);
Keypad myKeypad = Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);
Servo myservo;

void ReadCode()
{
  i = 0;                    //All variables set to 0
  a = 0;
  j = 0;

  while (keypressed != 'A') {                                   //The user press A to confirm the code otherwise he can keep typing
    keypressed = myKeypad.getKey();
    if (keypressed != NO_KEY && keypressed != 'A' ) {     //If the char typed isn't A and neither "nothing"
      lcd.setCursor(j, 1);                                 //This to write "*" on the LCD whenever a key is pressed it's position is controlled by j
      lcd.print("*");
      j++;
      if (keypressed == code[i] && i < sizeof(code)) {       //if the char typed is correct a and i increments to verify the next caracter
        a++;
        i++;
      }
      else
        a--;                                               //if the character typed is wrong a decrements and cannot equal the size of code []
    }
  }
  keypressed = NO_KEY;

}

void ReadPass()
{
  //All variables set to 0                 
  i2 = 0;                    
  a2 = 0;
  j2 = 0;

 //The user has to press A to confirm the code otherwise he can keep typing
  while (keypressed != 'A') 
  {                                   
    keypressed = myKeypad.getKey();
  }
    //If the char typed isn't A and neither "nothing"
  if (keypressed != NO_KEY && keypressed != 'A' ) 
  {
   //This to write "*" on the LCD whenever a key is pressed it's position is controlled by j     
      lcd.setCursor(j2, 1);                                 
      lcd.print("*");
      j2++;

      //if the char typed is correct a and i increments to verify the next caracter
      if (keypressed == code[i2] && i2 < sizeof(pass)) 
      {       
        a2++;
        i2++; 
      }
  }
  //if the character typed is wrong a decrements and cannot equal the size of code []
      else
        a2--; 
}
void OpenDoor()
{
  lcd.clear();
  lcd.setCursor(1, 0);
  lcd.print("Access Granted");
  lcd.setCursor(4, 1);
  lcd.print("WELCOME!!");
  myservo.write(90);
}

void setup()
{
  pinMode(buzzer, OUTPUT);
  pinMode(Led, OUTPUT);
  lcd.begin();                      // initialize the lcd
  lcd.backlight();
  lcd.begin ();
  lcd.setCursor(0, 0);
  lcd.print("*ENTER THE CODE*");
  lcd.setCursor(1 , 1);

  lcd.print("TO _/_ (Door)!!");      //What's written on the LCD you can change
  myservo.attach(11);
  myservo.write(0);
 pinMode(buzzer, OUTPUT);
  pinMode(Led, OUTPUT);
  lcd.begin();                      // initialize the lcd
  lcd.backlight();
  lcd.begin ();
  lcd.setCursor(0, 0);
  lcd.print("*ENTER THE CODE*");
  lcd.setCursor(1 , 1);

  lcd.print("TO _/_ (Door)!!");      //What's written on the LCD you can change
  myservo.attach(11);
  myservo.write(0);
 for (int i = 0 ; i < EEPROM.length() ; i++)
 {
    EEPROM.write(i, 0);             //Upload the code and change it to store it in the EEPROM
 }                                  //Then uncomment this for loop and reupload the code (It's done only once)

char code[]= {'1','2','3','4'};  //The default password
char pass[]= {'1','1','1','1'};  //The default password2
}

void loop()
{
  //Constantly waiting for a key to be pressed
  keypressed = myKeypad.getKey();  
  char pass[]= {'1','1','1','1'};  //The default password2             

  // * to open the lock
   if (keypressed == '*')
   {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.println("*ENTER THE CODE*"); 

    //Getting code function
    //The ReadCode function assign a value to a (it's correct when it has the size of the code array)
    ReadCode();

    if (count<=3)
    {
      //Open lock function if code is correct
    if (a == sizeof(code))
    {        
      OpenDoor();
    }  

    else
    {
      lcd.clear();
      lcd.setCursor(1, 0);
      lcd.print("CODE"); //Message to print when the code is wrong
      lcd.setCursor(6, 0);
      lcd.print("INCORRECT");
      lcd.setCursor(15, 1);
      lcd.print(" ");
      lcd.setCursor(4, 1);
      lcd.print("GET AWAY!!!");

      count++;
    }
    delay(2000);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("*ENTER THE CODE*");
    lcd.setCursor(1 , 1);

    //Return to standby mode it's the message do display when waiting
    lcd.print("TO _/_ (Door)!!");
    }

    else
    {
      //automatically turns on when user failed 3 times
      digitalWrite(Led, HIGH);
      delay(1000);
      digitalWrite(buzzer, HIGH);
      delay(1000);

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.println("*ENTER THE CODE*"); 

    //Getting code function
    //The ReadCode function assign a value to a (it's correct when it has the size of the code array)
    ReadPass();

    if (a == sizeof((pass))
    {
       OpenDoor();  
    }

    else
    {
      lcd.clear();
      lcd.setCursor(1, 0);
      lcd.print("CODE"); //Message to print when the code is wrong
      lcd.setCursor(6, 0);
      lcd.print("INCORRECT");
      lcd.setCursor(15, 1);
      lcd.print(" ");
      lcd.setCursor(4, 1);
      lcd.print("GET AWAY!!!");
    }
    delay(2000);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("*ENTER THE PASS*");
    lcd.setCursor(1 , 1);

    //Return to standby mode it's the message do display when waiting
    lcd.print("TO _/_ (Door)!!");
    }

   


    
    

Welcome to the forum

Your topic was MOVED to its current forum category as it is more suitable than the original as it is not an Introductory Tutorial

how can I move my question?

Why so many calls to lcd.begin() ? Do it just once in setup()

      if (a == sizeof((pass))

3 left brackets and only 2 right brackets !

Where does the loop() function end ?

Count the number of { and } carefully as they must be in pairs and yours aren't

If you use Auto Format in the IDE you will see that the last statement of the sketch is not a } on the left margin as it should be

1 Like

I have moved it

Thank you sir.

I read in an ancient textbook that even a fool can write a compiler for correct programs. The tricky bit is providing meaningful error messages for incorrect programs.

Modern compilers have become very good at this, but it can be useful to reflect that sometimes, all the compiler is really saying is that there's a problem and here's where I noticed it. The actual issue may well be earlier on in the code - quite often on the line above.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.