SunFounder Thales Kit for Raspberry Pi Pico, Release 1.0
5. Insert the Button, connect one side of it to the GP16 pin, then use a 10K resistor to connect the same side and
the negative bus. Do not forget to connect the other side to the positive power bus.
Note:
The color ring of 220 ohm resistor is red, red, black, black and brown.
The color ring of the 10k ohm resistor is brown, black, black, red and brown.
Code
When the program is started, the traffic light will switch in the order of red for 5 seconds, yellow for 2 seconds, green
for 5 seconds, and yellow for 2 seconds. If we (pedestrians) press the button, the red LED will be extended to 15
seconds, which will give us more time to cross the road.
import
machine
import
utime
import
_thread
led_red
=
machine
.
Pin(
15
, machine
.
Pin
.
OUT)
led_yellow
=
machine
.
Pin(
14
, machine
.
Pin
.
OUT)
led_green
=
machine
.
Pin(
13
, machine
.
Pin
.
OUT)
button
=
machine
.
Pin(
16
, machine
.
Pin
.
IN)
global
button_status
button_status
=
0
def
button_thread
():
global
button_status
while
True
:
if
button
.
value()
==
1
:
button_status
=
1
_thread
.
start_new_thread(button_thread, ())
while
True
:
if
button_status
==
1
:
led_red
.
value(
1
)
utime
.
sleep(
10
)
global
button_status
button_status
=
0
led_red
.
value(
1
)
utime
.
sleep(
5
)
led_red
.
value(
0
)
led_yellow
.
value(
1
)
utime
.
sleep(
2
)
led_yellow
.
value(
0
)
led_green
.
value(
1
)
utime
.
sleep(
5
)
led_green
.
value(
0
)
led_yellow
.
value(
1
)
utime
.
sleep(
2
)
led_yellow
.
value(
0
)
3.4. Projects
65
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 ...