if someone could take a look and see why I'm getting the error code. I've looked for all the correct "{}" and tried moving my functions around and putting the function names in the globals. I really don't know what else to look for.
My coding skills still need practice.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
long randomNumber;
int randomA;
int randomB;
int randomC;
int randomD;
int randomCode;
int codeVal;
int realNumber;
int realA;
int realB;
int realC;
int realD;
int value;
int count;
int state;
int lastState;
int counter;
int relayPin = 5;
int SW = 2;
int CLK = 9; // Pin 9 to clk on encoder
int DT = 8; // Pin 8 to DT on encoder
void setup() {
lcd.begin(16, 2);
randomSeed(analogRead(0));
pinMode (SW, INPUT);
pinMode (CLK, INPUT);
pinMode (DT, INPUT);
pinMode (relayPin, OUTPUT);
counter = 5;
count = 0;
lastState = digitalRead(CLK);
}
void loop() {
lcd.setCursor(0, 0);
lcd.print(" Code #");
lcd.setCursor(0, 1);
lcd.print(" Access #");
lcd.setCursor(11, 0);
lcd.print(randomCode);
if (count == 0){
randomGen();
}
if (digitalRead(SW) == HIGH) {
delay(500);
count++;
}
switch (count) { //RotPosition = counter
case 1:
select();
realA = (counter * 1000);
lcd.setCursor(11, 1);
lcd.print(counter);
break;
case 2:
lcd.setCursor(11, 1);
lcd.print("*");
select();
realB = (counter * 100);
lcd.setCursor(12, 1);
lcd.print(counter);
break;
case 3:
lcd.setCursor(12, 1);
lcd.print("*");
select();
realC = (counter * 10);
lcd.setCursor(13, 1);
lcd.print(counter);
break;
case 4:
lcd.setCursor(13, 1);
lcd.print("*");
select();
realD = (counter * 10);
lcd.setCursor(14, 1);
lcd.print(counter);
break;
case 5:
lcd.setCursor(14, 1);
lcd.print("*");
delay(500);
check();
break;
}
}
int select() {
state = digitalRead(CLK);
if (state != lastState) {
if (digitalRead(DT) != state) {
counter++;
}
else {
counter--;
}
}
if (digitalRead(SW) == HIGH) {
delay(500);
count++;
}
}
int check() {
realNumber = (realA + realB + realC + realD);
codeVal = map (randomCode, 9999, 1111, 1111, 9999);
if (codeVal == realNumber) {
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" * ACCESS ");
lcd.setCursor(0,1);
lcd.print(" GRANTED ");
delay(500);
digitalWrite(relayPin, HIGH);
delay(3000);
digitalWrite(relayPin, LOW);
count = 0;
counter = 5;
lcd.clear();
}
if (codeVal != realNumber) {
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" ACCESS ");
lcd.setCursor(0,1);
lcd.print(" DENIED ");
delay(3000);
count = 0;
counter = 5;
lcd.clear();
}
int randomGen() {
randomNumber = random(1, 10);
randomA = (randomNumber * 1000);
randomB = (randomNumber * 100);
randomC = (randomNumber * 10);
randomD = randomNumber;
randomCode = (randomA + randomB + randomC + randomD);
delay(100);
if (digitalRead(SW) == HIGH) {
delay(500);
count++;
}
return randomCode;
}