SunFounder Thales Kit for Raspberry Pi Pico, Release 1.0
(continued from previous page)
_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
)
• When the program is just running,
button_status
is assigned a value of 0, which means that the button has
not been pressed.
• In the new thread–button_thread, when the program detects that the button is pressed,
button_status
is
assigned the value 1.
• At the beginning of each cycle, it will detect whether the button has been pressed, if the button is pressed
(button_status == 1), the red light will be on for 10 seconds. Then
button_status
switch to 0, and wait for
the next button press.
The function of
global button_status
is to tell the program that we are going to modify the value of
button_status
, but if we just want to read the variable value, this line is not needed.
3.4.6 Two Kinds of Transistors
Transistor is a semiconductor device that controls a large current through a small current. Its function is to amplify
weak signals into larger amplitude signals, and can also be used as a non-contact switch. It is the core component of
electronic circuits.
This sounds a bit complicated. In simple words, some components use high-current (such as Buzzer). If the power
is directly supplied from the GPIO of the microcontroller, the power may be insufficient or the microcontroller may
be damaged. Then, the transistor has played a “dam” role here. Transistor receives the weak electrical signal from
the GPIO pin to control the turn-on and turn-off of the large current (from VCC to GND). In this way, high-current
components can be driven and the microcontroller can be protected.
This kit is equipped with two types of transistors, S8550 and S8050, the former is PNP and the latter is NPN. They
look very similar, and we need to check carefully to see their labels. When a High level signal goes through an NPN
transistor, it is energized. But a PNP one needs a Low level signal to manage it. Both types of transistor are frequently
used for contactless switches, just like in this experiment.
68
Chapter 3. For MicroPython User
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 ...