I need to compare 2 time variables in seconds.
sprintf(stopTime1, "%02d:%02d:%02d", SPhour1, SPmin1, SPsec1); //Get stop time from widget
stopTime1 = stopTime1Sec;
stopTime1Sec = ((hour()*3600) + (minute()*60) + second());
elapsedTimeOut1 = currentTimeSec - stopTime1Sec;
RemainFadeOut1 = ((FadeOutTime1 - elapsedTimeOut1)*1000); //Convert final time to millis
stopTime1 is a char type
stopTime1Sec is an unsigned long type
RemainFadeOut1 is an unsigned long type
elapsedTimeOut1 is an unsigned long type
The error I am getting is
incompatible types in assignment of 'long unsigned int' to 'char [9]'
How do I convert the time so that it can be compared with the other variables
Please post a complete program that shows the problem. It does not have to be your full program as long as it is complete.
This is the section of the programme which is causing problems. Basically the char is being assigned to an int.
//RTC & TIME IMPUT ATTRIBUTES & VARIABLES
char currentTime[9]; //RTC time
char currentDate[11]; //RTC date
unsigned long currentTimeSec;
char startTime1[9]; //Time input widget
char stopTime1[9]; //Time input widget
int SThour1; //Time input widget
int STmin1; //Time input widget
int STsec1; //Time input widget
int SPhour1; //Time input widget
int SPmin1; //Time input widget
int SPsec1; //Time input widget
int dayNumber1; //Time input widget
bool activeToday1 = false;
int Progress1;
//RTC & TIME IMPUT ATTRIBUTES & VARIABLES
char currentTime[9]; //RTC time
char currentDate[11]; //RTC date
unsigned long currentTimeSec;
char startTime1[9]; //Time input widget
char stopTime1[9]; //Time input widget
int SThour1; //Time input widget
int STmin1; //Time input widget
int STsec1; //Time input widget
int SPhour1; //Time input widget
int SPmin1; //Time input widget
int SPsec1; //Time input widget
int dayNumber1; //Time input widget
bool activeToday1 = false;
int Progress1;
system
June 11, 2019, 11:53am
4
sprintf(stopTime1, "%02d:%02d:%02d", SPhour1, SPmin1, SPsec1); //Get stop time from widget
What rubbish. That is NOT what that line of code does.
This is the section of the programme which is causing problems. Basically the char is being assigned to an int.
The ONLY assignment in either block of code is the assignment of false to activeToday1, which I can assure you is NOT causing a problem.
char stopTime1[9]; //Time input widget
stopTime1 = stopTime1Sec;
Does that make ANY sense to you?
char stopTime1[9]; //Time input widget
stopTime1 = stopTime1Sec;
What I am trying to here is take the stopTime which is in HH:MM:SS format give it another name stopTime1Sec then taking the stopTime1Sec and convert to seconds.
How would this be done then?
system
June 11, 2019, 12:23pm
6
How would this be done then?
Hint: There would be NO strings involved in the process. The number of seconds since midnight is simple matter of multiplying hours by 3600, multiplying minutes by 60, and adding those two values to the number of seconds.
You must, of course, use the appropriate type(s) for all intermediate calculations and the final value.
What rubbish. That is NOT what that line of code does.
The startTime1 gets its input from this Blynk Widget
BLYNK_WRITE(V11) //CH1 TIME IMPUT WIDGET
{
TimeInputParam t(param);
SThour1 = t.getStartHour();
STmin1 = t.getStartMinute();
STsec1 = t.getStartSecond();
SPhour1 = t.getStopHour();
SPmin1 = t.getStopMinute();
SPsec1 = t.getStopSecond();
dayNumber1 = weekday();
activeToday1 = false;
unsigned int OnDays1 = 0;
for (int i = 1; i <= 7; i++) //Process weekdays (1-Mon, 2-Tues, 3-Wed, 4-Thurs, 5-Fri, 6-Sat, 7-Sun)
{
if (t.isWeekdaySelected(i))
{
OnDays1++;
if(i==dayNumber1)
{
activeToday1 = true;
}
}
}
if (OnDays1 == 0)
{
activeToday1 = false;
}
}
system
June 11, 2019, 12:27pm
8
The startTime1 gets its input from this Blynk Widget
So? That does not make that useless comment right. The sprintf() function is not doing what the comment claims.