//chat gbt aided
const int buttonPin_Morning = 7; // The pin where the button is connected
const int buttonPin_Night_1 = 4; // The pin where the button is connected
const int buttonPin_Night_2 = 2; // The pin where the button is connected
const int ledPin_Morning = 13; // The pin where the LED is connected
const int ledPin_Night_1 = 12; // The pin where the LED is connected
const int ledPin_Night_2 = 10; // The pin where the LED is connected
bool ledState = false; // Current state of the LED
bool lastButtonState = HIGH;
bool currentButtonState;
bool ledState_Morning = false;
bool ledState_Night_1 = false;
bool ledState_Night_2 = false;
bool lastButtonState_Morning = HIGH;
bool currentButtonState_Morning;
bool lastButtonState_Night_1 = HIGH;
bool currentButtonState_Night_1;
bool lastButtonState_Night_2 = HIGH;
bool currentButtonState_Night_2;
void setup() {
pinMode(buttonPin_Morning, INPUT_PULLUP); // Use internal pull-up resistor
pinMode(buttonPin_Night_1, INPUT_PULLUP); // Use internal pull-up resistor
pinMode(buttonPin_Night_2, INPUT_PULLUP); // Use internal pull-up resistor
pinMode(ledPin_Morning, OUTPUT);
pinMode(ledPin_Night_1, OUTPUT);
pinMode(ledPin_Night_2, OUTPUT);
}
void loop() {
currentButtonState_Morning = digitalRead(buttonPin_Morning);
currentButtonState_Night_1 = digitalRead(buttonPin_Night_1);
currentButtonState_Night_2 = digitalRead(buttonPin_Night_2);
// Detect when the button is pressed (change from HIGH to LOW)
if (lastButtonState_Morning == HIGH && currentButtonState_Morning == LOW) {
ledState_Morning = !ledState_Morning; // Toggle the LED state switches state
digitalWrite(ledPin_Morning, ledState_Morning ? HIGH : LOW);
delay(200); // Debounce delay
}
// Detect when the button is pressed (change from HIGH to LOW)
if (lastButtonState_Night_1 == HIGH && currentButtonState_Night_1 == LOW) {
ledState_Night_1 = !ledState_Night_1; // Toggle the LED state switches state
digitalWrite(ledPin_Night_1, ledState_Night_1 ? HIGH : LOW);
delay(200); // Debounce delay
}
// Detect when the button is pressed (change from HIGH to LOW)
if (lastButtonState_Night_2 == HIGH && currentButtonState_Night_2 == LOW) {
ledState_Night_2 = !ledState_Night_2; // Toggle the LED state switches state
digitalWrite(ledPin_Night_2, ledState_Night_2 ? HIGH : LOW);
delay(200); // Debounce delay
}
lastButtonState_Morning = currentButtonState_Morning; //updates this button state to be last button state
lastButtonState_Night_1 = currentButtonState_Night_1; //updates this button state to be last button state
lastButtonState_Night_2 = currentButtonState_Night_2; //updates this button state to be last button state
}