FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
circuitpython/tests/pyb/timer_callback.py at master · ProGamerCode/circuitpython · GitHub
ProGamerCode
/
circuitpython
Public
forked from
adafruit/circuitpython
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
circuitpython
/
tests
/
pyb
/
timer_callback.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
49 lines (41 loc) · 1001 Bytes
Breadcrumbs
circuitpython
/
tests
/
pyb
/
timer_callback.py
Copy path
File metadata and controls
49 lines (41 loc) · 1001 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# check callback feature of the timer class
import
pyb
from
pyb
import
Timer
# callback function that disables the callback when called
def
cb1
(
t
):
print
(
"cb1"
)
t
.
callback
(
None
)
# callback function that disables the timer when called
def
cb2
(
t
):
print
(
"cb2"
)
t
.
deinit
()
# callback where cb4 closes over cb3.y
def
cb3
(
x
):
y
=
x
def
cb4
(
t
):
print
(
"cb4"
,
y
)
t
.
callback
(
None
)
return
cb4
# create a timer with a callback, using callback(None) to stop
tim
=
Timer
(
1
,
freq
=
100
,
callback
=
cb1
)
pyb
.
delay
(
5
)
print
(
"before cb1"
)
pyb
.
delay
(
15
)
# create a timer with a callback, using deinit to stop
tim
=
Timer
(
2
,
freq
=
100
,
callback
=
cb2
)
pyb
.
delay
(
5
)
print
(
"before cb2"
)
pyb
.
delay
(
15
)
# create a timer, then set the freq, then set the callback
tim
=
Timer
(
4
)
tim
.
init
(
freq
=
100
)
tim
.
callback
(
cb1
)
pyb
.
delay
(
5
)
print
(
"before cb1"
)
pyb
.
delay
(
15
)
# test callback with a closure
tim
.
init
(
freq
=
100
)
tim
.
callback
(
cb3
(
3
))
pyb
.
delay
(
5
)
print
(
"before cb4"
)
pyb
.
delay
(
15
)
Back
|
FazBrowse Home
|
New Git URL