expected constructor, destructor, or type conversion before '(' token

My code is:

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

int pirPin = 6;
int pirValue;
delay(61000)
void setup() {
pinMode(pirPin, INPUT);
lcd.begin(16, 2);
lcd.print(“Skye is awesome!”);
}

void loop() {

lcd.setCursor(4, 1);
if (pirValue = digitalRead(pirPin))
lcd.print(“WELCOME”);}
delay(6000);
else lcd.print(millis() / 1000);
}

Plz tell me what I have done wrong im new to this :confused:

Get rid of the delay before setup

Then you’ll have to fix the “else without previous else” error and/or mismatched brace

void loop() {

  lcd.setCursor(4, 1);
  if (pirValue = digitalRead(pirPin))
  lcd.print("WELCOME");}

That } ends the whole of loop() leaving a bunch of orphan code outside of any function. I don't think you meant to do that.

AutoFormat (Ctrl-T) in the IDE helps you spot things like that.

Steve

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

int pirPin = 6;
int pirValue;

void setup() {
pinMode(pirPin, INPUT);
lcd.begin(16, 2);
lcd.print(“JJ2020 is awesome!”);
delay(61000);
}

void loop() { //THIS IS WHERE THE IF/ELSE PROBLEM IS

lcd.setCursor(4, 1);
if (pirValue = digitalRead(pirPin))
lcd.print(“WELCOME”);
delay(6000);
else lcd.print(millis() / 1000);
}

If you spot any errors please say so in the comments :slight_smile:
Thankyou,
Jack

Hello JJ2020,

if (pirValue = digitalRead(pirPin)) lcd.print("WELCOME");

The if ends after the semicolon. So the else has no if.

Regards, bidouilleelec

Here is your loop() function Auto Formatted in the IDE

void loop()                                         //THIS IS WHERE THE IF/ELSE PROBLEM IS
{
  lcd.setCursor(4, 1);
  if (pirValue = digitalRead(pirPin))
    lcd.print("WELCOME");
  delay(6000);
  else lcd.print(millis() / 1000);
}

The only code dependent on the if is the lcd.print(), then there is an unconditional delay() before the else, hence the error message. If you want the delay() to be dependent on the test then put the dependent code in curly brackets like this

  if (pirValue = digitalRead(pirPin))
  {
    lcd.print("WELCOME");
    delay(6000);
  }
  else 
  {
    lcd.print(millis() / 1000);
  }

Note that I also chose to put the dependent code for the else in curly brackets as I feel it makes the code to be executed as a result of the if/else more obvious

(deleted)

Topics merged to avoid confusion and multiple answers in different topics