SunFounder Thales Kit for Raspberry Pi Pico, Release 1.0
•
utime.ticks_diff()
is used to output the time difference between two time nodes. The two time nodes
in this function are
utime.ticks_ms()
, the current program time (press the button) and the reference time
(light off) stored in the variable
timer_light_off
.
These two functions are usually used together to calculate the execution time of the program. Here we use it to
calculate the time from when the light turns off to when the button is pressed.
Finally, this time will be printed out.
(
"Your reaction time was "
+
str
(rection_time)
+
" milliseconds!"
)
Also see the reference here:
•
•
•
What more?
Playing with your friends will be more fun, why not add buttons and see who can press the buttons the fastest?
Please try it.
import
machine
import
utime
import
urandom
led
=
machine
.
Pin(
15
, machine
.
Pin
.
OUT)
left_button
=
machine
.
Pin(
14
, machine
.
Pin
.
IN)
right_button
=
machine
.
Pin(
16
, machine
.
Pin
.
IN)
def
button_press
(pin):
left_button
.
irq(handler
=
None
)
right_button
.
irq(handler
=
None
)
(continues on next page)
3.4. Projects
63
Summary of Contents for Thales Kit
Page 1: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 Jimmy SunFounder Jun 04 2021 ...
Page 2: ......
Page 4: ...ii ...
Page 6: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 2 CONTENTS ...
Page 140: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 136 Chapter 3 For MicroPython User ...
Page 164: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 160 Chapter 4 For Arduino User ...