//Region 1
// Set pin numbers
const int buttonPin1 = 2; // the number of the first pushbutton pin
const int buttonPin2 = 15; // the number of the second pushbutton pin
const int ledPinred = 5; // the number of the red LED pin (PWM capable)
const int ledPingreen = 18; // the number of the green LED pin (PWM capable)
const int ledPinblue = 19; // the number of the blue LED pin (PWM capable)
// Variables for storing the pushbutton states
int buttonState1 = 0;
int buttonState2 = 0;
int brightness = 0; // Variable to store LED brightness (0 to 255)
//Region 2
void setup() {
Serial.begin(115200);
// Initialize the pushbutton pins as input
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
// Initialize the LED pins as output (PWM capable)
pinMode(ledPinred, OUTPUT);
pinMode(ledPingreen, OUTPUT);
pinMode(ledPinblue, OUTPUT);
}
//Region 3
void loop() {
// Read the state of the pushbutton values
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
// Print button states to Serial Monitor
//Serial.print("Button 1 state: ");
//Serial.println(buttonState1);
//Serial.print("Button 2 state: ");
//Serial.println(buttonState2);
// Gradually increase brightness for red LED when button 1 is pressed
if (buttonState1 == HIGH) {
for (brightness = 0; brightness <= 255; brightness++) {
analogWrite(ledPinred, brightness); // Adjust red LED brightness
delay(10); // Slow down the brightness change
//Serial.println (buttonState1);
}
} else {
analogWrite(ledPinred, 0); // Turn red LED off
}
// Gradually increase brightness for green LED when button 2 is pressed
if (buttonState2 == HIGH) {
for (brightness = 0; brightness <= 100; brightness++) {
analogWrite(ledPingreen, brightness); // Adjust green LED brightness
Serial.println (brightness);
delay(100); // Slow down the brightness change
analogWrite(ledPingreen, 0); // Turn green LED off
}
} else {
analogWrite(ledPingreen, 0); // Turn green LED off
delay(1000); // Slow down the brightness change
}