Dual LED Control — Raspberry Pi Pico W simulation

Two LEDs connected to Raspberry Pi Pico GP13 and GP14 pins with current-limiting resistors.

An interactive Raspberry Pi Pico W circuit simulation you can run free in your browser on Velxio, by dunn-38688.

Components

Sketch code

const int redPin = 14;   // Red LED
const int whitePin = 13; // White/Green LED

void setup() {
  Serial.begin(9600);
  pinMode(redPin, OUTPUT);
  pinMode(whitePin, OUTPUT);
  
  // Start with lights off
  digitalWrite(redPin, LOW);
  digitalWrite(whitePin, LOW);
  Serial.println("System Ready. Type 'brake' or 'forward'.");
}

void loop() {
  if (Serial.available() > 0) {
    String command = Serial.readStringUntil('\n');
    command.trim();

    if (command == "brake") {
      digitalWrite(redPin, HIGH);
      digitalWrite(whitePin, LOW);
      Serial.println("Braking: Red ON, White OFF");
    } 
    else if (command == "forward") {
      digitalWrite(redPin, LOW);
      digitalWrite(whitePin, HIGH);
      Serial.println("Forward: White ON, Red OFF");
    }
  }
}

More projects by dunn-38688