Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years ago.
Converting time to integer help
I am trying to write a program whereby the function will be executed whenever the hours (24hr format) is X from RTC time.
#include "mbed.h"
void function(){
...
}
int main(){
set_time( ... );
while(1){
if(hour == X) {
function();
}
}
}
Your help will be greatly appreciated.
1 Answer
8 years ago.
Hello Tan,
You may try for example the following:
void function(){
...
}
int main(){
time_t my_time;
tm my_tm;
set_time( ... );
while (1) {
my_time = time(NULL);
my_tm = *localtime(&my_time);
if ((my_tm.tm_hour == X) && (my_tm.tm_sec == 0)) {
function();
}
...
}
}
But a more efficient solution is to use Erik Olieman's RTC library which enables to utilize RTC interrupts.
posted by 08 Nov 2017