Skip to content
This repository was archived by the owner on May 7, 2025. It is now read-only.

Commit 2f56f00

Browse files
committed
docs(timer): Added Example for BlynkTimer
1 parent 055bcf6 commit 2f56f00

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

BlynkTimer.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class BlynkTimer:
1414
'''Executes functions after a defined period of time'''
1515
_MAX_TIMERS = 16
1616

17-
def __init__(self, **kwargs):
17+
def __init__(self):
1818
self.timers = []
1919
self.ids = self._get_unique_id()
2020

@@ -83,7 +83,7 @@ def disable(self, timerId):
8383
return timerId
8484

8585
def run(self):
86-
'''Starts Timers'''
86+
'''Polls timers'''
8787
[t.run() for t in self.timers]
8888

8989

examples/timer.py

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""
2+
Blynk is a platform with iOS and Android apps to control
3+
Arduino, Raspberry Pi and the likes over the Internet.
4+
You can easily build graphic interfaces for all your
5+
projects by simply dragging and dropping widgets.
6+
7+
Downloads, docs, tutorials: http://www.blynk.cc
8+
Sketch generator: http://examples.blynk.cc
9+
Blynk community: http://community.blynk.cc
10+
Social networks: http://www.fb.com/blynkapp
11+
http://twitter.com/blynk_app
12+
13+
This example shows how to run functions after certain intervals
14+
15+
It will automagically call hello_word once after 2 seconds, and print_me
16+
every 5 seconds
17+
18+
You should only need one BlynkTimer instance for a project,
19+
as you can add multiple functions to it
20+
"""
21+
22+
import BlynkLib
23+
from BlynkTimer import BlynkTimer
24+
25+
BLYNK_AUTH = 'YourAuthToken'
26+
27+
# Initialize Blynk
28+
blynk = BlynkLib.Blynk(BLYNK_AUTH)
29+
30+
# Create BlynkTimer Instance
31+
timer = BlynkTimer()
32+
33+
34+
# Will only run once after 2 seconds
35+
def hello_world():
36+
print("Hello World!")
37+
38+
39+
# Will Print Every 5 Seconds
40+
def print_me():
41+
print("Thanks!")
42+
43+
44+
# Add Timers
45+
timer.set_timeout(2, hello_world)
46+
timer.set_interval(5, print_me)
47+
48+
49+
while True:
50+
blynk.run()
51+
timer.run()

0 commit comments

Comments
 (0)