Skip to content

Commit b188d6e

Browse files
committed
examples/hwapi: Add example for machine.time_pulse_us().
1 parent 5e90572 commit b188d6e

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

examples/hwapi/button_reaction.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import utime
2+
import machine
3+
from hwconfig import LED, BUTTON
4+
5+
# machine.time_pulse_us() function demo
6+
7+
print("""\
8+
Let's play an interesting game:
9+
You click button as fast as you can, and I tell you how slow you are.
10+
Ready? Cliiiiick!
11+
""")
12+
13+
while 1:
14+
try:
15+
delay = machine.time_pulse_us(BUTTON, 1, 10*1000*1000)
16+
print("You are as slow as %d microseconds!" % delay)
17+
except OSError:
18+
print("Well, you're *really* slow")
19+
utime.sleep_ms(10)

0 commit comments

Comments
 (0)