// FabAcademy 2026 - XIAO RP2040 // Button cycles LED: OFF -> ON -> BLINK -> OFF const int LED1 = 29; const int LED2 = 7; const int BUTTON1 = 0; const int BUTTON2 = 6; int stateLED1 = 0; int stateLED2 = 0; bool lastButton1 = HIGH; bool lastButton2 = HIGH; unsigned long previousMillis = 0; const long blinkInterval = 500; bool blinkState = LOW; void setup() { pinMode(LED1, OUTPUT); pinMode(LED2, OUTPUT); pinMode(BUTTON1, INPUT); pinMode(BUTTON2, INPUT); digitalWrite(LED1, LOW); digitalWrite(LED2, LOW); } void loop() { bool button1 = digitalRead(BUTTON1); bool button2 = digitalRead(BUTTON2); // BUTTON1 cambia estado LED1 if (button1 == LOW && lastButton1 == HIGH) { stateLED1++; if (stateLED1 > 2) stateLED1 = 0; delay(200); } // BUTTON2 cambia estado LED2 if (button2 == LOW && lastButton2 == HIGH) { stateLED2++; if (stateLED2 > 2) stateLED2 = 0; delay(200); } lastButton1 = button1; lastButton2 = button2; // control blink unsigned long currentMillis = millis(); if (currentMillis - previousMillis >= blinkInterval) { previousMillis = currentMillis; blinkState = !blinkState; } // LED1 comportamiento if (stateLED1 == 0) { digitalWrite(LED1, LOW); } else if (stateLED1 == 1) { digitalWrite(LED1, HIGH); } else if (stateLED1 == 2) { digitalWrite(LED1, blinkState); } // LED2 comportamiento if (stateLED2 == 0) { digitalWrite(LED2, LOW); } else if (stateLED2 == 1) { digitalWrite(LED2, HIGH); } else if (stateLED2 == 2) { digitalWrite(LED2, blinkState); } }