Arduino variable going blank after the first pass
Posted
by
user541597
on Stack Overflow
See other posts from Stack Overflow
or by user541597
Published on 2010-12-27T05:34:09Z
Indexed on
2010/12/31
10:54 UTC
Read the original article
Hit count: 254
I have an Arduino sketch that takes a timet and when that timet is equal to the current time it sets the new timet to timet + 2.
For example:
char* convert(char* x, String y)
{
int hour;
int minute;
sscanf(x, "%d:%d", &hour, &minute);
char buf[6];
if (y == "6")
{
if (hour > 17)
{
hour = (hour+6)%24;
snprintf(buf, 10, "%d:%d", hour, minute );
}
else
if (hour < 18)
{
//hour = hour + 6;
minute = (minute + 2);
snprintf(buf, 10, "%d:%d", hour, minute);
}
}
if (y == "12")
{
if (hour > 11)
{
hour = (hour+12)%24;
snprintf(buf, 10, "%d:%d", hour, minute );
}
else
if (hour < 12)
{
hour = hour + 12;
snprintf(buf, 10, "%d:%d", hour, minute);
}
}
if (y == "24")
{
hour = (hour+24)%24;
snprintf(buf, 10, "%d:%d", hour, minute );
}
return buf;
}
The sketch starts for example at 1:00am. timet is set to 1:02, at system time 1:02 timet is equal to the system time.
My loops looks like this:
if (timet == currenttime)
{
timet = convert(timet)
}
Whenever I check the value of timet it should equal 1:04, however I get the correct value at the first run after the execution of convert, however every time after that my timet value is blank.
I tried changing the code instead of using the if loop. I only run the convert function when I send for example t through the serial monitor. This works fine and outputs the correct timet after the execution of the convert function, So I figured the problem is in the if loop...
Any ideas?
© Stack Overflow or respective owner