int buttonPin = 2; // Pin connected to the push button
int ledPin = 8;   // Pin connected to the LED
int strobDelay = 500; // Delay between strobe flashes in milliseconds
boolean isOn = false; // Variable to track the state

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT_PULLUP); // Enable internal pull-up resistor
}

void loop() {
  // Read the state of the push button
  int buttonState = digitalRead(buttonPin);

  if (buttonState == LOW) { // Button is pressed
    delay(50); // Debounce delay
    buttonState = digitalRead(buttonPin); // Read the button state again

    if (buttonState == LOW) { // Button is still pressed
      isOn = !isOn; // Toggle the state

      if (isOn) {
        ledDance(); // Start the LED dance
      } else {
        digitalWrite(ledPin, LOW); // Turn off the LED
      }

      while (buttonState == LOW) {
        buttonState = digitalRead(buttonPin); // Wait for the button release
      }
    }
  }
}

void ledDance() {
  for (int i = 0; i < 500; i++) {
    digitalWrite(ledPin, HIGH); // Turn on the LED
    delay(strobDelay);
    digitalWrite(ledPin, LOW); // Turn off the LED
    delay(strobDelay);
  }
}
FPS: 0
Power: 0.00W