#include <Arduino.h> // Include necessary library (assuming Arduino)
int carRed = 13; // Assign pin number to car red light (might differ)
int carGreen = 12; // Assign pin number to car green light (might differ)
int button1 = 7; // Assign pin number to first button (might differ)
int button2 = 8; // Assign pin number to second button (might differ)
// Variable to keep track of the currently lit LED
int currentLED = carRed;
bool arduinoOn = false; // Variable to keep track of Arduino power state
void setup(){
pinMode(carRed, OUTPUT);
pinMode(carGreen, OUTPUT);
pinMode(button1, INPUT_PULLUP); // Button 1 with internal pull-up resistor
pinMode(button2, INPUT_PULLUP); // Button 2 with internal pull-up resistor
digitalWrite(carRed, LOW); // Initially turn on red light
}
void loop() {
// Check if button 2 is pressed to toggle the Arduino board power state
if (digitalRead(button2) == LOW) {
// Toggle the power state
arduinoOn = !arduinoOn;
// Add any necessary initialization if arduinoOn is true
if (arduinoOn) {
// Perform any necessary initialization here
}
// Debounce delay
delay(500);
}
// Check if Arduino is powered on
if (arduinoOn) {
int state = digitalRead(button1);
if (state == LOW) { // Button 1 is pressed (LOW due to pull-up)
digitalWrite(carRed, LOW);
digitalWrite(carGreen, LOW); // Turn off both lights
// Cycle through LEDs based on currentLED
if (currentLED == carRed) {
digitalWrite(carRed, HIGH);
currentLED = carGreen;
} else if (currentLED == carGreen) {
digitalWrite(carGreen, HIGH);
currentLED = carRed;
}
delay(500); // Debounce delay
}
// Add more conditions for other buttons if needed
}
}