SunFounder Thales Kit for Raspberry Pi Pico, Release 1.0
Code
When the program is running, the LED will alternate between gradually brightening and gradually dimming.
How it works?
As in the previous lesson, when using a pin, its input/output mode needs to be defined first. Then we can write values
to it, a function
in
loop()
assigns ledPin a PWM wave (brightness)which will add or decrease 5 for
each cycle.
analogWrite
(ledPin, brightness);
// change the brightness for next time through the loop:
brightness
=
brightness
+
fadeAmount;
Use an if statement to limit the range of
brightness
to 0-255, the
brightness
will accumulate from 0 to 255
and then decrement from 255 to 0, alternating repeatedly.
if
(brightness
<=
0
||
brightness
>=
255
) {
fadeAmount
= -
fadeAmount;
}
•
•
•
4.2.3 Warning Light
From the name of GPIO (General-purpose input/output), we can see that these pins have both input and output func-
tions. In the previous two lessons we used the output function, in this project, we will use the input function to input
the Slide value, and then control the LED to blink, like a warning light.
148
Chapter 4. For Arduino User
Содержание 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 ...