
SunFounder Thales Kit for Raspberry Pi Pico, Release 1.0
Wiring
In this experiment, we will use 5 LEDs to show the light intensity. The higher the light intensity is, the more LEDs
will light up, vice versa.
Code
How it works?
const int
ledPins[]
=
{
11
,
12
,
13
,
14
,
15
};
const int
photocellPin
=
A0;
//photoresistor attach to A0
int
sensorValue
=
0
;
// value read from the sensor
int
Level
=
0
;
// sensor value converted into LED 'bars'
First of all, there are still various initialization definitions, setting pins and setting initial values of variables.
In order to quickly set the input/output status and HIGH/LOW for the 5 LEDs in the following code, here we use the
array
ledPin[]
to define the 5 LEDs connected to the corresponding pins of the Pico.
The element number of the array usually starts from 0. For example,
ledPin[0]
refers to GPIO11, and
ledPin[4]
refers to GPIO15.
•
void
setup
()
{
Serial
.
begin
(
9600
);
// start serial port at 9600 bps:
for
(
int
i
=
0
; i
<
5
; i
++
)
{
pinMode
(ledPins[i],
OUTPUT
);
// make all the LED pins outputs
}
}
In
setup()
using the
for()
statement set the 5 pins to OUTPUT. The variable
i
is added from 0 to 5, and the
pinMode()
function sets pin11 to pin15 to OUTPUT in turn.
4.2. Projects
155
Содержание 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 ...