How to assign the 'time input' param to a global var

The usual method for the time input widget is:

    TimeInputParam t(param);
    ...stuff.. with e.g. t.getStartHour(), t.isWeekdaySelected(), etc. 

problem however is is that if you want to check whether ‘its time’ you have to run blynk_write every (e.g.) minute to compare the set param to the current rtc time.

I’d like to pull these two apart and have blynk_write used for what its made for: update parameters when received from the app

and a timer that checks whether ‘its time’ every minute.

HOWEVER that means that either ‘t’ or ‘param’ need to be assigned to a global variable so you can access them outside of the blynk_write function.

QUESTION: how do you do that? Neither param nor t are ‘regular’ variables.

I’m aware that you can store e.g. t.getStartHour() in a global var as its an int. But that does not apply for t.isWeekdaySelected() so that won’t work.
I’m also aware that its possible to pass on the blynk param by reference:

void setSchedule(const BlynkParam& param) {         
  int value = param.asInt();

but I wouldn’t know how to pass on a variable by reference to a global var. Any clue anyone?

I do that here in this example.

int SThour;
int STmin;
int STsec;
int SPhour;
int SPmin;
int SPsec;
BLYNK_WRITE(V1) {  // Called whenever setting Time Input Widget
  TimeInputParam t(param);
  SThour = t.getStartHour();
  STmin = t.getStartMinute();
  STsec = t.getStartSecond();
  SPhour = t.getStopHour();
  SPmin = t.getStopMinute();
  SPsec = t.getStopSecond();

Why not? It is a boolean result is it not?

I feared you would come up with that, so I hoped I had elaborated enough on it. I’ve seen your example, actually I’ve read ALL time input posts I could find and your example does not answer my question (see topic title). Don’t get me wrong, your effort to answer all open posts is hugely appreciated (by me and i guess others as well) but sometimes you’re trying to give an alternative answer completely missing the point of the question as is in this case.

in your example you check the time but not whether its the right day. And yes there IS a method to do that as well but it involves calling BLYNK_WRITE() routine every minute by using Blynk.syncVirtual() in a timed function. That is NOT the method I’m looking for.

So let me rephrase it another way I want to use this:

 timer.setInterval(1000*60, checkSchedule());  // check if current time falls with time input

where weekday are relevant and without using Blynk.syncVirtual or any other method to involve BLYNK_WRITE()

to elaborate on your remark

void checkSchedule(){
  	TimeInputParam t(param); // will only work if param is global!!! HOW do I do this?
	if( t.isWeekdaySelected(weekday()) ){...} //and yes I'm aware that blynk week and time lib are one day apart


Or…im completer missing your point and or is possible to store that function as bool? In that case please elaborate

By definition I did answer your question :stuck_out_tongue_winking_eye: by showing how to assign the Time Input parameters to a Global Variable… but your actual question(s) deverges into a couple of directions…

  • Global Variable

  • Use of t.isWeekdaySelected() as Global Variable

  • Check variable status on a regular basis without calling the actual BLYNK_WRITE() function… done by assigning initial values to Global Variables and checking them in a timed function instead.

So, since you pretty much answered all your own questions while asking them… I was confused as to your ACTUAL question… Thus my responding post is designed to engage further dialogue to hopefully resolve both question and answer clarity.

I admit my past topic examples were simple… I rarely use this widget. But I think of this widget’s parameters much like other merged widget parameters (Joystick & zeRGBa for example)… break them out into their individual components, assign as required and process as needed.

So, have you tried something like this?

bool MonWeekDay;
bool TuesWeekDay;
bool WedWeekDay;

Honestly, I think a simple int would work just as well…

BLYNK_WRITE(V1) {  // Called whenever setting Time Input Widget
  TimeInputParam t(param);
  MonWeekDay = t.isWeekdaySelected(weekday(1)); // Check if Monday is selected or not (1 = Yes, 0 = No)
  TuesWeekDay = t.isWeekdaySelected(weekday(2)); // Check if Tuesday is selected or not (1 = Yes, 0 = No)
  WedWeekDay = t.isWeekdaySelected(weekday(3)); // Check if Wednesday is selected or not (1 = Yes, 0 = No)
void SomeTimedLoop() {
if MonWeekDay == 1) {
  // do stuffs on Mondays
if TuesWeekDay == 1) {
  // do stuffs on Tuesdays
if WedWeekDay == 1) {
  // do stuffs on Wednesdays

Sorry for delayed editing… I hit post before I was finished my ‘untested code’ :stuck_out_tongue_winking_eye:

You’re right that its good to initiate the conversation! And yes I have considered breaking them up into 7 bools, but its a less ideal solution (but a solution nonetheless). The main question remains though which is: how assign param to a global var? OR how to assign ‘t’ to a global var.
I guess I can work with you’re given solution but I’m still curious to the answer to my main question, moreover as I can imagine that it will come in handy in the future!
And ‘sorry’ really is not in place, you’re timely responses are all one can wish for :smiley:

I guess this is a typical dev question as they should know how to approach this.

OK… I guess I glossed over this one :blush: … short of hacking the library, the answer is probably “not an option”… Just use the normal methods described above. and in the Docs, for this and all similar merged parameters.

Parse it in the Blynk Function and use those globally assigned factors throughout your code.

thnx, Ill check it out tomorrow.