I was writing some code, the code worked perfectly fine before but now the sketchwill not compile because of the error message 'expected unqualified-id before 'else''. Here is my code and the error is on line 216
//rgb led, lock, matrix, lcd, RFID
#include <SPI.h> // SPI library
#include <MFRC522.h> // RFID library
#include <FastLED.h> //RGB LED Library
#include <Keypad.h> //Matrix library
#include <LiquidCrystal.h> //LCD library
#define LOCK 12
//RGB LED stuff
#define LED 13
#define NUM_LED 8
CRGB led[NUM_LED];
#define LED_TYPE WS2811 //RGB led model
//matrix stuff
const int ROW_NUM = 4; //four rows
const int COLUMN_NUM = 3; //three columns
char keys[ROW_NUM][COLUMN_NUM] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};
byte pin_rows[ROW_NUM] = {11, 10, 9, 8};
byte pin_column[COLUMN_NUM] = {7, 6, 5};
Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );
const String password = "1234"; // change your password here
String input_password;
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
//LCD stuff
const int rs = 4, en = 3, d4 = 22, d5 = 24, d6 = 26, d7 = 28;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
//RFID stuff
/*
Pins SPI UNO Mega2560 Leonardo
1 (NSS) SAD (SS) 10 53 10
2 SCK 13 52 SCK1
3 MOSI 11 51 MOSI1
4 MISO 12 50 MISO1
5 IRQ * * *
6 GND GND GND GND
7 RST 9 ? Reset
8 +3.3V (VCC) 3V3 3V3 3.3V
Not needed
1 on ICPS header
*/
const int pinRST = 2;
const int pinSDA = 53;
MFRC522 mfrc522(pinSDA, pinRST); // Set up mfrc522 on the Arduino
void setup() {
SPI.begin(); // open SPI connection
mfrc522.PCD_Init(); // Initialize Proximity Coupling Device (PCD)
Serial.begin(9600);
pinMode(LOCK, OUTPUT);
pinMode(LED, OUTPUT);
FastLED.addLeds<LED_TYPE, LED, GRB>(led, NUM_LED);
input_password.reserve(32);
FastLED.clear();
fill_solid(led, NUM_LED, CRGB::Blue);
FastLED.show();
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("safe ready");
}
void loop() {
char key = keypad.getKey();
if (key) {
Serial.println(key);
if (key == '*') {
input_password = "";
lcd.clear();
delay(10);
lcd.print("cleared!");
FastLED.clear();
fill_solid(led, NUM_LED, CRGB::Blue);
FastLED.show();
} else if (key == '#') {
if (password == input_password) {
lcd.clear();
lcd.print("Unlocked!");
Serial.println("password is correct");
FastLED.clear();
fill_solid(led, NUM_LED, CRGB::Green);
FastLED.show();
digitalWrite(LOCK, HIGH);
delay(5000);
FastLED.clear();
fill_solid(led, NUM_LED, CRGB::Blue);
FastLED.show();
digitalWrite(LOCK, LOW);
}
else {
Serial.println("password is incorrect, try again");
FastLED.clear();
fill_solid(led, NUM_LED, CRGB::Red);
FastLED.show();
lcd.clear();
lcd.print("incorrect password!");
// digitalWrite(LOCK,LOW); (already low)
//when password is incorrect
delay(5000);
FastLED.clear();
fill_solid(led, NUM_LED, CRGB::Blue);
FastLED.show();
}
} /* else {
// Serial.println("password being filled out");
FastLED.clear();
fill_solid(led, NUM_LED, CRGB::Blue);
FastLED.show();
// when password is being filled out */
}
input_password = "";
} else {
input_password += key;
// digitalWrite(LOCK,LOW);
// when password is cleared
/* FastLED.clear();
fill_solid(led, NUM_LED, CRGB::Red);
FastLED.show();
*/
}
//RFID code
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
//Show UID on serial monitor
Serial.print("UID tag :");
String content = "";
byte letter;
for (byte i = 0; i < mfrc522.uid.size; i++)
{
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], HEX));
}
Serial.println();
Serial.print("Message : ");
content.toUpperCase();
if (content.substring(1) == "53 1F C1 18") //change here the UID of the card/cards that you want to give access
{
/* Serial.println("Authorized access, white card");
Serial.println();
delay(500); */
lcd.clear();
lcd.print("Unlocked!");
FastLED.clear();
fill_solid(led, NUM_LED, CRGB::Green);
FastLED.show();
digitalWrite(LOCK, HIGH);
delay (5000);
lcd.clear();
lcd.print("Safe ready!");
FastLED.clear();
fill_solid(led, NUM_LED, CRGB::Blue);
FastLED.show();
digitalWrite(LOCK, LOW);
}
else {
Serial.println(" Access denied");
Serial.println();
delay(500);
lcd.clear();
lcd.print("wrong tag");
FastLED.clear();
fill_solid(led, NUM_LED, CRGB::Red);
FastLED.show();
digitalWrite(LOCK, LOW);
delay(10000);
lcd.clear();
lcd.print("safe ready!");
FastLED.clear();
fill_solid(led, NUM_LED, CRGB::Blue);
FastLED.show();
}