Hello!
I recently started making a keypad door lock and decided to add an lcd. I keep getting this error and i don't know why.
Error:
Arduino: 1.8.13 (Windows 10), Board: "Arduino Uno"
C:\Users\ephra\OneDrive\Documents\Arduino\keypadlock\keypadlock.ino: In function 'void setup()':
keypadlock:9:3: error: 'lcd' was not declared in this scope
lcd.begin(16, 2); // put your LCD parameters here
^~~
C:\Users\ephra\OneDrive\Documents\Arduino\keypadlock\keypadlock.ino: At global scope:
C:\Users\ephra\OneDrive\Documents\Arduino\keypadlock\keypadlock.ino:17:18: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
char* password = "6543"; //We set the password. In this case „123“
^~~~~~
C:\Users\ephra\OneDrive\Documents\Arduino\keypadlock\keypadlock.ino: In function 'void setup()':
keypadlock:47:6: error: redefinition of 'void setup()'
void setup()
^~~~~
C:\Users\ephra\OneDrive\Documents\Arduino\keypadlock\keypadlock.ino:7:6: note: 'void setup()' previously defined here
void setup()
^~~~~
C:\Users\ephra\OneDrive\Documents\Arduino\keypadlock\keypadlock.ino: In function 'void setLocked(int)':
keypadlock:106:3: error: a function-definition is not allowed here before '{' token
{
^
keypadlock:115:1: error: 'lcd' was not declared in this scope
lcd.print("Please Enter The Passcode.");
^~~
exit status 1
'lcd' was not declared in this scope
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Code:
#include <Keypad.h> //Include Keypad and servo library
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <LiquidCrystal.h>
#include <Servo.h>
Servo servoblue; //The servo is called „servoblue“ from now on
char* password = "6543"; //We set the password. In this case „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
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()
{
#include <LiquidCrystal_I2C.h>
char key = keypad.getKey();
if (key == '*' || key == '#')
{
position = 0;
setLocked(true);
}
if (key == password[position])
{
position ++;
}
if (position == 4) //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.
lcd.print("Please Enter The Passcode.");
}
else //if the lock is open..
{
#include <LiquidCrystal_I2C.h>
#include <LiquidCrystal.h>
#include <Wire.h>
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.
}
}