expected unqualified-id before 'if'
I believe my code is already correct but there is an error
Arduino: 1.8.19 (Windows 10), Board: "Arduino Uno"
streetlight_transmitter:46:1: error: expected unqualified-id before 'if'
if ( digitalRead( light1 ) == 1) {
^~
streetlight_transmitter:55:1: error: expected unqualified-id before 'else'
else {
^~~~
streetlight_transmitter:65:1: error: expected unqualified-id before 'if'
if ( digitalRead( light2 ) == 1) {
^~
streetlight_transmitter:73:1: error: expected unqualified-id before 'else'
else {
^~~~
streetlight_transmitter:84:1: error: expected unqualified-id before 'if'
if ( digitalRead( light3 ) == 1) {
^~
streetlight_transmitter:92:1: error: expected unqualified-id before 'else'
else {
^~~~
streetlight_transmitter:100:1: error: expected unqualified-id before 'if'
if ( digitalRead( light4 ) == 1) {
^~
streetlight_transmitter:108:1: error: expected unqualified-id before 'else'
else {
^~~~
streetlight_transmitter:116:1: error: expected declaration before '}' token
}
^
exit status 1
expected unqualified-id before 'if'
this are the error message
const int light1 = A0;
const int light2 = A1;
const int light3 = A2;
const int light4 = A3;
const int pin1 = 10;
const int pin2 = 11;
const int pin3 = 12;
const int pin4 = 13;
#include <Wire.h>
#include <virtuabotixRTC.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 16, 2);
virtuabotixRTC myRTC(6, 7, 8);
void setup() {
Serial.begin(9600);
lcd.begin ();
lcd.backlight();
myRTC.setDS1302Time(14, 37, 6, 7, 5, 11, 2022);
}
void loop() {
lcd.clear();
myRTC.updateTime();
lcd.setCursor(0, 0);
lcd.print(myRTC.dayofmonth);
lcd.print("/");
lcd.print(myRTC.month);
lcd.print("/");
lcd.print(myRTC.year);
lcd.setCursor(0, 1);
lcd.print(myRTC.hours);
lcd.print(":");
lcd.print(myRTC.minutes);
lcd.print(":");
lcd.print(myRTC.seconds);
delay(2000);
lcd.clear();
}
if ( digitalRead( light1 ) == 1) {
digitalWrite(pin1, HIGH);
lcd.print("ST1:BAD");
delay(650);
lcd.clear();
}
else {
digitalWrite(pin1, LOW);
lcd.print("ST1:GOOD");
delay(650);
lcd.clear();
}
if ( digitalRead( light2 ) == 1) {
digitalWrite(pin2, HIGH);
lcd.print("ST2:BAD");
delay(650);
lcd.clear();
}
else {
digitalWrite(pin2, LOW);
lcd.print("ST2:GOOD");
delay(650);
lcd.clear();
}
if ( digitalRead( light3 ) == 1) {
digitalWrite(pin3, HIGH);
lcd.print("ST3:BAD");
delay(650);
lcd.clear();
}
else {
digitalWrite(pin3, LOW);
lcd.print("ST3:GOOD");
delay(650);
lcd.clear();
}
if ( digitalRead( light4 ) == 1) {
digitalWrite(pin4, HIGH);
lcd.print("ST4:BAD");
delay(650);
lcd.clear();
}
else {
digitalWrite(pin4, LOW);
lcd.print("ST4:GOOD");
delay(650);
lcd.clear();
}
}
}
the code