Add two int variables

Hello, I tried to setup an int variable that combines 2 int variables. I have to do this because I want to combine an hour and a minute variable. In my code I may have some extra lines for troubleshooting.

#include "Arduino.h"
#include "uRTCLib.h"

// uRTCLib rtc;
uRTCLib rtc(0x68);

int DateTime = rtc.hour() * 10 + rtc.minute();
int NowTime = rtc.hour()*100+rtc.minute();

void setup() {
  Serial.begin(9600);
  delay(3000); // wait for console opening

  URTCLIB_WIRE.begin();

  // Comment out below line once you set the date & time.
  // Following line sets the RTC with an explicit date & time
  // for example to set January 13 2022 at 12:56 you would call:
  // rtc.set(second, minute, hour, dayOfWeek, dayOfMonth, month, year)
  // set day of week (1=Sunday, 7=Saturday)
}

void loop() {
  rtc.refresh();


  Serial.print(rtc.hour());
  Serial.print(':');
  Serial.println(rtc.minute());
  Serial.println(NowTime);
  
  delay(1000);
}

However this is my serial output:
18:50
0
18:50
0
18:50
0
18:50
0
18:50
0
18:50
0
18:50
0

Does anyone know what to do?

You are not in excel

You don’t define formulas and they are magically applied when you read the variable. You need to have the formula in the loop

1 Like

Thank you so much, I'm new to arduino so i didn't know it had to be in the loop. This solution works.

good to hear

you should take some time to practice a bit with C++ programming. there are tons of on line tutorials like C++ Introduction to get you started where the web site lets you type and try code directly on line. It helps anchor knowledge and you don’t get distracted by terminal command lines and files on your machine etc… (but there is advertising).

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