I am new with Arduino and have almost no experience with it. For the first time, I am getting a compiling code error that I cannot figure out how to solve. This is my code:
##include <Keypad.h>
#include<LiquidCrystal.h>
#include "DHT.h"
LiquidCrystal lcd (5, 4, 3, 2, 1, 0);
const byte rows = 4;
const byte cols = 3;
char key[rows][cols] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'','0','#'}
};
byte rowPins[rows] = {9,10,11};
byte colPins[cols] = {6,7,8};
Keypad keypad= Keypad(makeKeymap(key),rowPins,colPins,rows,cols);
#define DHTPIN A0
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
#define led A1
int alarm_temp = 30;
int alarm_humi = 85;
unsigned long abc = 0;
char customKey;
const long interval = 1000;
int menu=0;
int mode=0;
char password="5523";
int currentposition=0;
void setup() {
pinMode(led,OUTPUT);
lcd.begin(16,2);
lcd.clear();
dht.begin();
}
void loop()
{
if(currentposition==0)
{
displayscreen();
}
int pass ;
char code=keypad.getKey();
if(code!=NO_KEY)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("PASSWORD:");
lcd.setCursor(7,1);
lcd.print(" ");
lcd.setCursor(7,1);
for(pass=0;pass<=currentposition;++pass)
{
lcd.print("*");
}
if (code==password[currentposition])
{
++currentposition;
if(currentpostion==4)
{
ok();
currentpostion=0;
}
}
else { matkhausai(); currentposition=0;}
}
}
void ok(){
customkey = keypad.getKey();
if (customkey){
lcd.clear();
lcd.setCursor(6,0);
lcd.print(customKey);
}
if(customKey=='3'){
menu=1;
mode=0;
while(menu==1){
customKey = customKeypad.getKey();
lcd.setCursor(6,0);
lcd.print("SETUP");
lcd.setCursor(0,1);
if(mode==1){
lcd.print("TEMP-H:");
if(customKey=='B'){alarm_temp++;
lcd.setCursor(9,1);
lcd.print(alarm_temp);
}
if(customKey=='F'){alarm_temp--;
lcd.setCursor(9,1);
lcd.print(alarm_temp);
}
}
if(mode==2){lcd.print("TEMP-L:");}
if(mode==3){lcd.print("HUMI-H:");}
if(mode==4){lcd.print("HUMI-L:");}
if(customKey=='7'){ // MODE
mode++;
if(mode==5){
lcd.clear();
lcd.setCursor(6,0);
lcd.print("EXIT"); goto ex;}
}
}
ex:;
}
}
void matkhausai()
{
delay(500);
lcd.clear();
lcd.setCursor(1,0);
lcd.print("CODE");
lcd.setCursor(6,0);
lcd.print("SAI ROI");
lcd.setCursor(15,1);
lcd.println(" ");
lcd.setCursor(4,1);
lcd.println("SAI!!!");
lcd.setCursor(13,1);
lcd.println(" ");
Serial.println("MAT KHAU BI SAI ROI");
delay(3000);
lcd.clear();
displayscreen();
}
void displayscreen()
{
lcd.setCursor(0,0);
lcd.println("NHAP MAT KHAU");
}
}
And this is the error that I get:
C:\Users\Administrator\Documents\Arduino\sketch_apr14b\sketch_apr14b.ino: In function 'void loop()':
sketch_apr14b:58:4: error: 'currentpostion' was not declared in this scope
if(currentpostion==4)
^
C:\Users\Administrator\Documents\Arduino\sketch_apr14b\sketch_apr14b.ino: In function 'void ok()':
sketch_apr14b:68:3: error: 'customkey' was not declared in this scope
customkey = keypad.getKey();
^
sketch_apr14b:80:14: error: 'customKeypad' was not declared in this scope
customKey = customKeypad.getKey();
^
C:\Users\Administrator\Documents\Arduino\sketch_apr14b\sketch_apr14b.ino: At global scope:
sketch_apr14b:134:1: error: expected declaration before '}' token
}
^
Using library Keypad in folder: C:\Program Files (x86)\Arduino\libraries\Keypad (legacy)
Using library LiquidCrystal at version 1.0.7 in folder: C:\Program Files (x86)\Arduino\libraries\LiquidCrystal
Using library DHT_sensor_library-1.4.2 in folder: C:\Program Files (x86)\Arduino\libraries\DHT_sensor_library-1.4.2 (legacy)
exit status 1
'currentpostion' was not declared in this scope
How can I solve this?
Thanks for the help!