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
Содержание Thales Kit
Страница 1: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 Jimmy SunFounder Jun 04 2021 ...
Страница 2: ......
Страница 4: ...ii ...
Страница 6: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 2 CONTENTS ...
Страница 10: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 6 Chapter 1 Introduction to Raspberry Pi Pico ...
Страница 12: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 8 Chapter 2 What is Included in This Kit ...
Страница 13: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 2 1 Components List 2 1 Components List 9 ...
Страница 42: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 38 Chapter 2 What is Included in This Kit ...
Страница 140: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 136 Chapter 3 For MicroPython User ...
Страница 164: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 160 Chapter 4 For Arduino User ...