SunFounder Thales Kit for Raspberry Pi Pico, Release 1.0
sensorValue
=
analogRead
(photocellPin);
//read the value of A0
Level
=
map
(sensorValue,
0
,
1023
,
0
,
5
);
// map to the number of LEDs
Serial
.
println
(Level);
delay
(
10
);
In
loop()
, read the analog value of the photocellPin(A0) and store to the variable sensorValue.
The
map()
function is used to map 0-1023 to 0-5. It means that the value range of the photoresistor (0-1023) is
equally divided into 5 levels, 0-204.8 belongs to Level 0, 204.9-409.6 belongs to Level 1, and 819.2-1023 belong to
Level 4. If the value of variable
sensorValue
is 300 at this time, then
Level
is equal to 1.
•
for
(
int
i
=
0
; i
<
5
; i
++
)
{
if
(i
<=
Level )
//When i is smaller than Level, run the following code.
{
digitalWrite
(ledPins[i],
HIGH
);
// turn on LEDs less than the level
}
else
{
digitalWrite
(ledPins[i],
LOW
);
// turn off LEDs higher than level
}
}
Now we need to find a way to display the brightness level at this time with LEDs.
The
for()
statement is used here to perform loop detection in the
ledPin[]
array. If the element bit in the array
is less than the value of
Level
, the corresponding GPIO is set to high level, that is, the corresponding LED is lit. If
Level
is equal to 1, turn on the LEDs on GPIO11 and GPIO12.
4.2.6 Doorbell
A buzzer is a great tool in your experiments whenever you want to make some sounds. In this lesson, we will learn
how to drive a passive buzzer to build a simple doorbell.
Two types of buzzers are included in the kit. We need to use passive buzzer. Turn them around, the one with exposed
PCB is we want.
The buzzer needs to use a transistor when working, here we use S8050.
156
Chapter 4. For Arduino 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 ...