#define buttonBluePin 0 // Pin for the blue pushbutton
#define buttonRedPin 1 // Pin for the red pushbutton
#define buttonGreenPin 2 // Pin for the green pushbutton
#define buttonYellowPin 3 // Pin for the yellow pushbutton
#define redPin 6 // Pin for the red LED
#define greenPin 7 // Pin for the green LED
#define bluePin 8 // Pin for the blue LED
void setup() {
// put your setup code here, to run once:
Serial1.begin(115200);
Serial1.println("Hello, Raspberry Pi Pico!");
pinMode(buttonBluePin, INPUT);
pinMode(buttonRedPin, INPUT);
pinMode(buttonGreenPin, INPUT);
pinMode(buttonYellowPin, INPUT);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
delay(1); // this speeds up the simulation
// Read the state of each pushbutton
int buttonRedState = digitalRead(buttonRedPin);
int buttonGreenState = digitalRead(buttonGreenPin);
int buttonBlueState = digitalRead(buttonBluePin);
// Control the RGB LED based on button presses
if (buttonRedState == LOW) {
setColor(255, 0, 0); // Red
} else if (buttonGreenState == LOW) {
setColor(0, 255, 0); // Green
} else if (buttonBlueState == LOW) {
setColor(0, 0, 255); // Blue
} else {
// If no button is pressed, turn off the LED
setColor(0, 0, 0);
}
}
// Function to set the color of the RGB LED
void setColor(int redValue, int greenValue, int blueValue) {
analogWrite(redPin, redValue);
analogWrite(greenPin, greenValue);
analogWrite(bluePin, blueValue);
}