Me parece mejor
const int buttonPin1 = 2;
const int ledPin = 13;
const int buttonPin2 = 4;
int i = 0;
void setup()
{
pinMode(buttonPin1, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
}
void loop()
{
int pin1State = digitalRead(buttonPin1);
int pin2State = digitalRead(buttonPin2);
if (i == 0) {
if (pin1State == LOW)
{
i = 1;
}
}
if (i == 1) {
if (pin2State == LOW)
{
i = 2;
}
}
if (i == 2)
{
digitalWrite(ledPin, HIGH);
i = 3;
}
if (i == 3) {
if (pin2State == LOW)
{
i = 4;
}
}
if (i == 4) {
if (pin1State == LOW)
{
i = 5;
}
}
if (i == 5)
{
delay(500);
digitalWrite(ledPin, LOW);
i = 0;
}
}
Porque sino cuando i es 0 no se sabe si hay que apagar o encender.
De cualquier modo prueba tu código porque puedo estar equivocado y estar bien como lo has hecho. ![]()
Saludos