Any way to compare "time" and "int"?

trying to make it so that when the time from DS3231 is equal to the set alarm time, the buzzer of the alarm will go off. however, i get an error saying that i cannot compare the 2. error is second last line. do i need to rewrite the code?

#include <DS3231.h>
#include <IRremote.h>
#include <IRremoteInt.h>
#include <LiquidCrystal.h> 
#include <Wire.h>
#include <stdlib.h>
DS3231 rtc (SDA, SCL);
LiquidCrystal lcd(1, 2, 4, 5, 6, 7);
int buzzerPin = 10;
int rc = 9;
IRrecv irrecv(rc);
decode_results results;
long num[10] = {0xFF6897, 0xFF30CF, 0xFF18E7, 0xFF7A85, 0xFF10EF, 0xFF38C7, 0xFF5AA5, 0xFF42BD, 0xFF4AB5, 0xFF52AD};
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int setAlarm = 0;


void setup() {
  lcd.begin(16, 2);
  rtc.begin();
  irrecv.enableIRIn();
}

void loop() {
    lcd.setCursor(0,0);
    lcd.print("Time: ");
    lcd.print(rtc.getTimeStr());
    lcd.setCursor(0,0);
    getAlarm();
}
void getAlarm(){
  if (irrecv.decode(&results)){
    Serial.println(results.value, HEX);
    irrecv.resume();
    if(results.value==0xFFB04F){
        setAlarm=1;
    }else if(results.value==0xFFFFFFFF){
      setAlarm = setAlarm;  
    }
  }
  if(digitalRead(buzzerPin)==HIGH){
    setAlarm=5;  
  }
  while(setAlarm==1){
    lcd.setCursor(0,0);
    lcd.print("Set Hour");
    lcd.setCursor(0,1);
    if(irrecv.decode(&results)){
      for(int i = 0; i<10; i++){
        if(results.value==num[i]){
          a = a*10+i;
        }else if(results.value==0xFFFFFFFF){
          a = a;  
        }
        irrecv.resume();
      }
      if(a<24){
        lcd.print(a);
        if(results.value==0xFFB04F){
          setAlarm=2;
        }
      }else{
        lcd.clear();
        setAlarm = 1;
        a=0;
      }
    }
  }
  while(setAlarm==2){
    lcd.setCursor(0,0);
    lcd.print("Set Minute");
    lcd.setCursor(0,1);
    if(irrecv.decode(&results)){
      for(int i = 0; i<10; i++){
        if(results.value==num[i]){
          b = b*10+i;
        }else if(results.value==0xFFFFFFFF){
          b = b;  
        }else if(results.value==0xFFB04F){
          setAlarm++;
        }
        irrecv.resume();
      }
      lcd.print(a);
      lcd.print(':');
      if(b<60){
        lcd.print(b);
        if(results.value==0xFFB04F){
          setAlarm=3;
        }
      }else{
        lcd.clear();
        setAlarm = 2;
        b=0;
      }
    }
  }
  while(setAlarm==3){
    lcd.setCursor(0,0);
    lcd.print("Set Second");
    lcd.setCursor(0,1);
    if(irrecv.decode(&results)){
      for(int i = 0; i<10; i++){
        if(results.value==num[i]){
         c = c*10+i;
        }else if(results.value==0xFFFFFFFF){
          c = c;  
        }else if(results.value==0xFFB04F){
          setAlarm++;
        }
        irrecv.resume();
      }
      lcd.print(a);
      lcd.print(':');
      lcd.print(b);
      lcd.print(':');
      if(c<60){
        lcd.print(c);
        if(results.value==0xFFB04F){
          setAlarm=4;
        }
      }else{
        lcd.clear();
        setAlarm = 3;
        c=0;
      }        
    }
  }
  while(setAlarm==4){
    lcd.setCursor(0,1);
    lcd.print("Alarm: ");
    if(a<10)lcd.print("0");
    lcd.print(a);
    lcd.print(':');
    if(b<10)lcd.print("0");
    lcd.print(b);
    lcd.print(':');
    if(c<10)lcd.print("0");
    lcd.print(c);
    if(results.value==0xFFB04F){
      setAlarm=0;
    }
  }

  if(rtc.getTime() == getAlarm){
    tone(buzzerPin, 100);
    a=0;
    b=0;
    c=0;
  }
  if(irrecv.decode(&results)){
    if(results.value==0xFFA25D){
      a=0;
      b=0;
      c=0; 
      lcd.setCursor(0,1);
      lcd.clear();
    }
  }
}

So, we've got to read the code, and guess the error?

No thanks.

They're global.
crt0 will set them to zero for you.

I doubt the error is in the second to last line as that line contains only
}
AWOL's comment might not be eloquent but he's right, we need to know what the error is and where, you have provided neither.

Please copy the exact error text and post in code tags, and identify where it occurs.

If there's an error in the code then obviously the code should be rewritten to correct the error.

Thank you

exit status 1
no match for 'operator==' (operand types are 'Time' and 'int')

this line

 if(rtc.getTime() == getAlarm){
    tone(buzzerPin, 100);
    a=0;
    b=0;
    c=0;
  }

Compare a time to a function pointer?

Come on, the standard way to do this is using Epoch times.

I see that you are still entrenched with obfuscated variable names like a, b, c... which I mentioned in your other thread.

getAlarm() is a void function so doesn't return anything to compare to.

...even if you call it.

That's a weird name for a function that returns nothing!

On a quick glance I found the following mistakes in your sketch:

if(rtc.getTime() == getAlarm){

  1. getTime() might quite likely either return a time structure (probably like DateTime) or the time in seconds. Please check the library you are using regarding the return value ...
  2. This line compares the return value/structure of rtc.getTime() with the address of the function getAlarm().
  3. getAlarm() is declared as void ... It will not return anything comparable to anything else than .. void ...
  4. If a,b,c shall be the alarm time (hour, minute, second) these values have to be compared with the actual time.

For time in seconds see

                                   // Rtc.GetTime() returns the "time_t" time value:
                                    // this is universal, absolute, UTC based, arithmetic time,
      time_t now = Rtc.GetTime();   // counted as seconds since Jan 1, 2000 00:00:00.
                                    // Unhappily the time.h libray does not takes into account "leap seconds"
                                    // (See: https://en.wikipedia.org/wiki/Leap_second)

Or read here for the structure:

https://create.arduino.cc/projecthub/MisterBotBreak/how-to-use-a-real-time-clock-module-ds3231-bc90fe

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