I am a beginner when it comes to Arduino and tinkercad, I'm not really sure what the problem is here but I am trying to create a keypad and LCD lock. At first, it said that setlock was not declared in the scope but then I added 'boolean setLocked' but then the error just changed to saying that setLocked cannot be used as a function. Any help will be extremely appreciated and please talk to me as if I am very dumb lol I am just starting this course with no prior knowledge. Thanks!
boolean setLocked;
#include <LiquidCrystal.h>
#include <Keypad.h>
#define redLED 10
#define greenLED 11
char* password="1212";
int positions = 0;
const byte rows = 4;
const byte columns = 4;
char keyMap [rows] [columns] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins [rows] = {1, 2, 3, 4};
byte columnsPins [columns] = {5, 6, 7, 8};
Keypad myKeypad = Keypad (makeKeymap(keyMap), rowPins, columnsPins, rows, columns);
LiquidCrystal lcd (A0, A1, A2, A3, A4, A5);
void setup() {
lcd.begin(16, 2);
pinMode(redLED, OUTPUT);
pinMode(greenLED, OUTPUT);
setLocked(true);
}
void loop() {
char whichKey = myKeypad.getKey();
lcd.setCursor (0,0);
lcd.print ("Hello");
lcd.setCursor(0,1);
lcd.print("Please enter the password");
if(whichKey == '*' || whichKey =='#'|| whichKey =='A' || whichKey =='B'|| whichKey =='C' || whichKey =='D') {
positions=0;
setLocked(true);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("The password is incorrect");
delay(500);
lcd.clear();
}
if(whichKey == password [positions]) {
positions ++;
}
if(positions == 4){
setLocked(false);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("!Correct!");
delay(3000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("End Arduino");
lcd.setCursor(0, 1);
lcd.print("Thank you for trying me out")
delay(5000);
lcd.clear();
}
delay(100);
}
void setLocked(int locked)
if(locked){
digitalWrite(redLED, HIGH);
digitalWrite(greenLED, LOW);
}
else{
digitalWrite(redLED, LOW);
digitalWrite(greenLED, HIGH);
}
}