Making getTimeStr compatible with an int function

is there any way to make getTimeStr() compatible with getAlarm? I tried converting getAlarm to string, but nothing changed

if(rtc.getTimeStr() == getAlarm){
    tone(buzzerPin, 100);
    a=0;
    b=0;
    c=0;
  }
/*Alarm Clock*/
#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 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.getTimeStr() == 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();
      noTone(buzzerPin)
    }
  }
}

What are you trying to achieve?

getAlarm is a function that returns nothing (void), and you are doing a comparison from within the getAlarm function (that is, you are calling it recursively)?

is getTimeStr() a valid function? Doesn't exist in my DS3232 library, but I know there are multiple.

basically, when the clocks time is equal to the alarms time, the alarm will go off. i forgot about the void thing so thanks. yes in my library it is a function

I don't think you should be trying to call getAlarm from inside getAlarm?

In my library there is a DS3231 function to do what you want...

bool checkIfAlarm(byte Alarm); 
			// Checks whether the indicated alarm (1 or 2, 2 default);
			// has been activated.

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