[SOLVED] Timer Widget Example

I have searched and searched but I can’t find any basic examples of code for the Timer Widget.

I know it can be linked to a virtual pin but haven’t figured out much more than this.

Just to be clear it is the widget that lets you set a start and end time for a particular event (light LED, start motor etc).

I am using an Arduino Nano with Serial USB.

Can anyone direct me to a sample sketch?

There is not much to tell about it. You attach the widget to either a physical or virtual pin and it will trigger a HIGH/LOW at the times you set in the app. You can easily try it with pin 13 on your Nano (the internal LED).

Be aware though that if you put the time of start in the past, it will only trigger on the next round! So if it’s 4.00 and you set the timer to 3.30 it will send a HIGH to the pin the next day :slight_smile:

Thanks but I’m looking for the library requirements etc. Most widgets have a basic example to work through but I can’t find anything for the Timer.

Because you don’t have to do anything in your sketch. The timer is basically App-only. You can’t do stuff with it in your sketch (well, you can, but that’s the creative part).

So there is no example sketch beause the magic happens in the Blynk.run() part and the App.

ok so as long as I set up a virtual pin in my sketch and the required action it will trigger on and off at the scheduled times?

That’s the idea :smile:

Nothing more too it, but of course you can manipulate the virtual pin with other program logic in combination with an override button.

if((button1 == 1) && (vpin1AttachedToTimer ==1))
else if((button1 == 1) && (vpin1AttachedToTimer == 0))

Pseudo code ofcourse, but you get the idea.

We will add an example for timer, thanks for the feedback.

But overall, it’s really that simple. Just configure wiidget in the app. If it’s digital or analog - it will turn on/off automatically at given times (even if your phone is offline)

If you would like to trigger a set of actions, use Virtual Pins approach:

BLYNK_WRITE(V1) //Button Widget is writing to pin V1
  int pinData = param.asInt(); 
  if (pinData == 1)
     //wake up
     //make me coffee
     //open the blinds 


Thanks Pavel and Lichtsignaal. As you say it is very simple. My first timer has just activated, still waiting for the kettle to boil :smile:
Pavel second last brace should be a closing, not open brace.