SunFounder Thales Kit for Raspberry Pi Pico, Release 1.0
Code
After the code has run, toggle the Slide switch to one side and the LED will flash. Toggle to the other side and the
LED will go out.
How it works?
For switchs, we need to set their mode to
INPUT
in order to be able to get their values.
void
setup
() {
// initialize the LED pin as an output:
pinMode
(ledPin,
OUTPUT
);
// initialize the switch pin as an input:
pinMode
(switchPin,
INPUT
);
}
Read the status of the
switchPin
in loop() and assign it to the variable
switchState
.
switchState
=
digitalRead
(switchPin);
•
If the
switchState
is HIGH, the LED will flash.
if
(switchState
==
HIGH
)
{
// turn LED on:
digitalWrite
(ledPin,
HIGH
);
delay
(
1000
);
digitalWrite
(ledPin,
LOW
);
delay
(
1000
);
}
Otherwise, turn off the LED.
else
{
digitalWrite
(ledPin,
LOW
);
}
4.2.4 Table Lamp
In the previous lessons, we have used the digital input on the Pico. For example, a button can change the pin from low
level (off) to high level (on). This is a binary working state.
However, Pico can receive another type of input signal: analog input. It can be in any state from fully closed to fully
open, and has a range of possible values. The analog input allows the microcontroller to sense the light intensity, sound
intensity, temperature, humidity, etc. of the physical world.
Usually, a microcontroller needs an additional hardware to implement analog input-the analogue-to-digital converter
(ADC). But Pico itself has a built-in ADC for us to use directly.
150
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 ...