/*All-in-one Starter Kit for PICO 2
Lezione 1 - Controllo dei LED
Codipe per il controllo simultaneo dei LED.
Modificando il codice, possiamo ottenere l’effetto
dei LED che si accendono e si spegono a intervalli regolari.
Hardware richiesto
All-in-one Starter Kit per Pico2 ×1
Cavo USB ×1
*/
// Define the pin connected to the red LED as pin 18
#define Red_LED 18
// Define the pin connected to the yellow LED as pin 20
#define Yellow_LED 20
// Define the pin connected to the green LED as pin 19
#define Green_LED 19
// Function for initialization operations, including hardware initialization, display initialization, and UI initialization
void setup() {
// Set the red LED pin to output mode to control the LED to turn on or off
pinMode(Red_LED, OUTPUT);
// Set the yellow LED pin to output mode
pinMode(Yellow_LED, OUTPUT);
// Set the green LED pin to output mode
pinMode(Green_LED, OUTPUT);
digitalWrite(Red_LED, LOW);
digitalWrite(Green_LED, LOW);
digitalWrite(Yellow_LED, LOW);
}
void loop() {
// Read the current state of the Red_LED pin
int Red_LEDState = digitalRead(Red_LED);
// Read the current state of the Green_LED pin
int Green_LEDState = digitalRead(Green_LED);
// Read the current state of the Yellow_LED pin
int Yellow_LEDState = digitalRead(Yellow_LED);
{
if (Red_LEDState == HIGH) {
digitalWrite(Red_LED, LOW);
}
// If the Red_LED is currently LOW, set it to HIGH
else {
digitalWrite(Red_LED, HIGH);
}
// If the Green_LED is currently HIGH, set it to LOW
if (Green_LEDState == HIGH) {
digitalWrite(Green_LED, LOW);
}
// If the Green_LED is currently LOW, set it to HIGH
else {
digitalWrite(Green_LED, HIGH);
}
// If the Yellow_LED is currently HIGH, set it to LOW
if (Yellow_LEDState == HIGH) {
digitalWrite(Yellow_LED, LOW);
}
// If the Yellow_LED is currently LOW, set it to HIGH
else {
digitalWrite(Yellow_LED, HIGH);
}
}
delay(1000);
}
Loading
pi-pico-w
pi-pico-w