#define B_button_pin 1
#define B_led_pin 20
#define R_button_pin 2
#define R_led_pin 18
void setup() {
// initialize digital pins for LEDS as an output and buttons as INPUTS
pinMode(B_led_pin, OUTPUT);
pinMode(B_button_pin, INPUT_PULLUP);
pinMode(R_led_pin, OUTPUT);
pinMode(R_button_pin, INPUT_PULLUP);
Serial1.begin(115200); // opens serial port, sets data rate to 115200 bps
Serial1.println("Input B to turn blue LED and R to turn red LED");
}
bool B_button_up = true; // bool holds one of two values, true or false
bool R_button_up = true;
// the setup function runs once when you press reset or power the board
void loop() {
if (Serial1.available()) {
char comdata = char(Serial1.read());
if (comdata == 'B') {
digitalWrite(B_led_pin, HIGH);
Serial1.print("you typed: ");
Serial1.println(comdata);
delay(500);
digitalWrite(B_led_pin, LOW);
}
if (comdata == 'R') {
digitalWrite(R_led_pin, HIGH);
Serial1.print("you typed: ");
Serial1.println(comdata);
delay(500);
digitalWrite(R_led_pin, LOW);
}
}
// Check Blue Button
if (digitalRead(B_button_pin) == LOW && B_button_up) {
digitalWrite(B_led_pin, HIGH);
Serial1.println("blue button down");
B_button_up = false;
}
if (digitalRead(B_button_pin) == HIGH && !B_button_up) {
digitalWrite(B_led_pin, LOW);
Serial1.println("blue button up");
B_button_up = true;
}
// Check Red Button
if (digitalRead(R_button_pin) == LOW && R_button_up) {
digitalWrite(R_led_pin, HIGH);
Serial1.println("red button down");
R_button_up = false;
}
if (digitalRead(R_button_pin) == HIGH && !R_button_up) {
digitalWrite(R_led_pin, LOW);
Serial1.println("red button up");
R_button_up = true;
}
delay(50); // Simple debounce delay for button presses
}
pico:GP0
pico:GP1
pico:GND.1
pico:GP2
pico:GP3
pico:GP4
pico:GP5
pico:GND.2
pico:GP6
pico:GP7
pico:GP8
pico:GP9
pico:GND.3
pico:GP10
pico:GP11
pico:GP12
pico:GP13
pico:GND.4
pico:GP14
pico:GP15
pico:GP16
pico:GP17
pico:GND.5
pico:GP18
pico:GP19
pico:GP20
pico:GP21
pico:GND.6
pico:GP22
pico:RUN
pico:GP26
pico:GP27
pico:GND.7
pico:GP28
pico:ADC_VREF
pico:3V3
pico:3V3_EN
pico:GND.8
pico:VSYS
pico:VBUS
btn2:1.l
btn2:2.l
btn2:1.r
btn2:2.r
btn3:1.l
btn3:2.l
btn3:1.r
btn3:2.r
r1:1
r1:2
r2:1
r2:2
led1:A
led1:C
led2:A
led2:C