#include // ---------- SENSOR ---------- #define SENSOR_PIN D2 // IR sensor int lastState = 1; // ---------- LED STRIP ---------- #define LED_PIN D1 #define TOTAL_LEDS 60 Adafruit_NeoPixel strip(TOTAL_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800); // ---------- CONTROL ---------- bool goalActive = false; unsigned long goalStartTime = 0; const int goalDuration = 2000; // 2 seconds unsigned long lastBlinkTime = 0; bool ledState = false; const int blinkInterval = 100; // blinking speed (ms) void setup() { Serial.begin(115200); pinMode(SENSOR_PIN, INPUT); strip.begin(); strip.clear(); strip.show(); Serial.println("Goal + LED system ready"); } void loop() { int currentState = digitalRead(SENSOR_PIN); // Detect goal (falling edge) if (lastState == 1 && currentState == 0 && !goalActive) { Serial.println("GOAL!! ⚽"); goalActive = true; goalStartTime = millis(); } lastState = currentState; // ---------- ANIMATION ---------- if (goalActive) { unsigned long currentTime = millis(); // Blinking if (currentTime - lastBlinkTime > blinkInterval) { lastBlinkTime = currentTime; ledState = !ledState; if (ledState) { setAllGreen(); } else { strip.clear(); strip.show(); } } // End of animation (2 seconds) if (currentTime - goalStartTime > goalDuration) { goalActive = false; strip.clear(); strip.show(); } } } // ---------- FUNCTIONS ---------- void setAllGreen() { for (int i = 0; i < TOTAL_LEDS; i++) { strip.setPixelColor(i, strip.Color(0, 255, 0)); } strip.show(); }