// Configuring the pin connected to the button
const int buttonPin = 2;
// Configuring the output pins
const int outputPin1 = 4;
const int outputPin2 = 5;
// Variable to save the button state
int buttonState = 0;
// Variable to save the last button state
int lastButtonState = 0;
// Variable to count the number of button presses
int buttonPresses = 0;
void setup() {
// Setting the button as input
pinMode(buttonPin, INPUT);
// Setting the outputs as outputs
pinMode(outputPin1, OUTPUT);
pinMode(outputPin2, OUTPUT);
}
void loop() {
// Reading the button state
buttonState = digitalRead(buttonPin);
// Checking if the button state has changed
if(buttonState != lastButtonState){
// If the button was pressed
if(buttonState == HIGH){
// Increase the counter
buttonPresses ++;
// If it's the first press, turn on output 1
if(buttonPresses == 1){
digitalWrite(outputPin1, HIGH);
delay(500);
digitalWrite(outputPin1, LOW);
}
// If it's the second press, turn on output 2
else if(buttonPresses == 2){
digitalWrite(outputPin2, HIGH);
delay(500);
digitalWrite(outputPin2, LOW);
// Reset the counter
buttonPresses = 0;
}
}
}
// Save the current button state as the last state
lastButtonState = buttonState;
}