What's the problem with this? "expected constructor, destructor, or type conversion before '(' token"

#include <DHT.h>
#include <DHT_U.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <virtuabotixRTC.h>
// Creation of the Real Time Clock Object

virtuabotixRTC myRTC(6, 7, 8);

// variables sensor
int sensor = 2;
int temp;
int hum;

int bhome = 10; //button home
int baset = 4; //button alarm set menu / set alarm
int bmas = 5; //button alarm +
int bmenos = 9; //button alarm -

pinMode(bhome, INPUT_PULLUP);
pinMode(baset, INPUT_PULLUP);
pinMode(bmas, INPUT_PULLUP);

int ah = 12; //alarm hour
int am = 0; //alarm minute
int as = 0; // alram second

int nowsec = 0; //seconds now
//strings para momentos temporales
String str = "a";

//int menu 0->home 1-> alarm
int menu = 0;

DHT dht(sensor, DHT11);
LiquidCrystal_I2C lcd(0x27, 16, 2);

//millis setup

const unsigned long eventInterval = 1000;
unsigned long previousTime = 0;

void setup() {
  // Set the current date, and time in the following format:
  // seconds, minutes, hours, day of the week, day of the month, month, year
  myRTC.setDS1302Time(5, 20, 18, 7, 7, 5, 2023);
  dht.begin();
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Hola, Alma!");
  lcd.setCursor(4, 1);
  lcd.print(":D");
  delay(2000);
  clearlcd();

  Serial.begin(9600);
}

void loop(){



  myRTC.updateTime();

  if(digitalRead(bhome) == LOW){
    clearlcd();
    menu = 0;
  }

  if(digitalRead(baset) == LOW){
    clearlcd();
    menu = 1;
  }
  if (nowsec < myRTC.seconds and menu == 0){ /* This is the event */
    Serial.println("homemenu");
    homee();/* Event code */
    
    /* Update the timing for the next time around */
  }
  
  if(nowsec < myRTC.seconds and menu == 1){
    Serial.println("alarmmenu starts");
    alarmmenu();
    
  }
}

void homee(){
  // This allows for the update of variables for time or accessing the individual elements.
  myRTC.updateTime();
  // Start printing elements as individuals
  temp = dht.readTemperature();
  hum = dht.readHumidity();
  
  lcd.setCursor(0, 0);
  
  add0(myRTC.dayofmonth);
  lcd.print(str);
  
  lcd.print("/");
  
  add0(myRTC.month);
  lcd.print(str);
  
  lcd.print("/");

  add0(myRTC.year);
  lcd.print(str);
  lcd.setCursor(12, 0);

  add0(temp);
  lcd.print(str);
  lcd.print((char)223);
  lcd.print("C");
  
  lcd.setCursor(0, 1); 

  add0(myRTC.hours);
  lcd.print(str);
  
  lcd.print(":");

  add0(myRTC.minutes);
  lcd.print(str);

  lcd.print(":");

  add0(myRTC.seconds);
  nowsec = myRTC.seconds;
  lcd.print(str);
  
  lcd.setCursor(12, 1);

  add0(hum);
  lcd.print(str);
  lcd.print("%");
}

void clearlcd(){
  lcd.setCursor(0, 0);
  lcd.print("                ");
  lcd.setCursor(0, 1);
  lcd.print("                ");
}

void add0(int num){
  if (num < 10){
    str = String(num);
    str = "0"+str;
  }
  else{
    str = String(num);
  }
}

void alarmmenu(){
  myRTC.updateTime();
  nowsec = myRTC.seconds;
  lcd.setCursor(0,0);
  lcd.print("Set your alarm");
  lcd.setCursor(5, 2);

}`Use code tags to format code for the forum`

Welcome to the forum

Please post the full error message copied from the IDE using the button provided for the purpose

Please use code tags when posting the error message

Arduino: 1.8.19 (Windows Store 1.8.57.0) (Windows 10), Board: "Arduino Uno"

sketch_dht_lcs_ds_buttons:20:8: error: expected constructor, destructor, or type conversion before '(' token

 pinMode(bhome, INPUT_PULLUP);

        ^

sketch_dht_lcs_ds_buttons:21:8: error: expected constructor, destructor, or type conversion before '(' token

 pinMode(baset, INPUT_PULLUP);

        ^

sketch_dht_lcs_ds_buttons:22:8: error: expected constructor, destructor, or type conversion before '(' token

 pinMode(bmas, INPUT_PULLUP);

        ^

exit status 1

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



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Thanks in advance!

You have to put pinMode in a function, like setup.

Thanks!

The error you're encountering is likely due to the fact that the printDoubleDigit function is missing from the code. You can add the following function definition to resolve the issue:

void printDoubleDigit(int num) {
  if (num < 10) {
    str = "0" + String(num);
  } else {
    str = String(num);
  }
}

By including this function, the code will be able to properly print double-digit numbers with leading zeros on the LCD.

@kalilinux25 if you are going to use AI generated content when providing help here, it must be done responsibly. Your use of it in this topic and others is irresponsible.

Just as with any other information you find on the Internet, you must carefully evaluate AI-generated content for accuracy, relevance, and appropriateness within the context. Copy/pasting without giving any thought to the information is irresponsible, regardless of the source of that information. If you are not able to make such an evaluation, then please don't share the content here on the forum.

Thanks in advance for your cooperation.

2 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.