My code does not function


#include <Keypad.h> //Include Keypad and servo library

#include <Servo.h>

Servo servoblue; //The servo is called „servoblue“ from now on

char* password = "123";

int position = 0;

const byte ROWS = 4; //In this two lines we define how many rows and columns

const byte COLS = 3; //our keypad has

char keys[ROWS][COLS] = { //The characters on the keys are defined here

{'#', '0', '*'},

{'9', '8', '7'},

{'6', '5', '4'},

{'3', '2', '1'}

};

byte rowPins[ROWS] = {5, 6, 7, 8}; //The connection with the arduino is

byte colPins[COLS] = {2, 3, 4}; //listed here

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

int redLED = 12; //The red LED is connected to pin 12

int greenLED = 13; //The green LED is connected to pin 13

setLocked(true)

}

void setup()

{

pinMode(redLED, OUTPUT); //The LEDs are defined as Output

pinMode(greenLED, OUTPUT);

servoblue.attach(11); //The servo is connected to pin 11

setLocked(true);

}

void loop()

{

char key = keypad.getKey();

if (key == " * " || key == " # ") If the lock is open it can be locked again by pushing "*" or "#" on the //keypad

position = 0;

setLocked(true); //The command to close the lock after „*“ or „#“ is pushed

}

if (key == password[position])

{

position ++;

}

if (position == 3) //This part defines how many digits our code will have.In this case we have 3 digits //(123).

{

setLocked(false);

}

{
delay(100)

}

void setLocked(int locked)

{

if (locked) // If the lock is closed..

{

digitalWrite(redLED, HIGH); //..the red LED should light up..

digitalWrite(greenLED, LOW); //..the green LED not..

servoblue.write(90); //and the servo should turn to a 90 degree position.

}

else //if the lock is open..

{

digitalWrite(redLED, LOW); //..the red LED should be off..

digitalWrite(greenLED, HIGH); //..and the green LED should light up..

servoblue.write(0); //..and the servo should turn to a 0 degree position.

}

}

And errors message:

C:\Users\Famille\Documents\Arduino\Keypad_lock\Keypad_lock.ino:8:18: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

char* password = "123";

^

Keypad_lock:39:10: error: expected constructor, destructor, or type conversion before '(' token

setLocked(true)

^

Keypad_lock:41:1: error: expected declaration before '}' token

}

^

exit status 1
expected constructor, destructor, or type conversion before '(' token

Hello, I need help because being a novice in programming I wanted to know what was the problem in this program and if possible if someone could correct me or tell me the changes to do. Thank you in advance !!

int greenLED = 13; //The green LED is connected to pin 13

setLocked(true)

}

Neither the setLocked nor the } should be there.

Please remember to use code tags when posting code.

(Also, this was never a bootloader issue)

Padlock2:
Hello, I need help because being a novice in programming I wanted to know what was the problem in this program and if possible if someone could correct me or tell me the changes to do. Thank you in advance !!

What is this doing above setup()?

setLocked(true)
}

This look like a comment was not marked as a comment:

  if (key == " * " || key ==  " # ") If the lock is open it can be locked again by pushing "*" or "#" on the //keypad

You have a bunch of code between the end of loop() and the start of setLocked(). Perhaps you ended loop() too early or forgot a '{' in your 'if' statement?

}


if (key == password[position])
{
  position ++;
}


if (position == 3) //This part defines how many digits our code will have.In this case we have 3 digits //(123).
{
  setLocked(false);
}




{
  delay(100)
}

After fixing those errors the code compiled... with warnings. For example, it does not make sense to compare a character (key) to a string of three characters (" * "). Even removing the spaces leaves you with a string constant ("") and not a character constant (''). Change those to character constants.

You don't reset 'position' to zero if the key entry doesn't match. That means you can keep pressing digits until you eventually hit each of the three digits. Hitting 123456789012345678901234567890 would open the lock no matter what three-digit code you selected. Better change it to:

  if (key == password[position])
  {
    position ++;
  }
  else
  {
    position = 0;
  }