change detection - LED on at program start when I'd like it to be off

Hello - I have a code help request. I have code that is counting how many times a button has been pushed - which I got from here.

It's going ok and I'm so happy to find all these great tutorials - but because basically it is using modulo and turning on an LED when the result is 0 - it means that the LED is on when the program starts. Any ideas on how to start with the LED off and then have to press the button 4 times to turn it on?

Thanks, Rachel

code snippet:

if (buttonPushCounter % 4 == 0) {

digitalWrite(ledPin, HIGH);

} else {
digitalWrite(ledPin, LOW);
}

}

In principle, just swap the LOW and HIGH.

Better alternative in my opinion

In the beginning of your sketch, place

#define LED_ON LOW

Below your snippet rewritten

 if (buttonPushCounter % 4 == 0)
 {
    // led on
    digitalWrite(ledPin, LED_ON);

  }
  else
  {
    // led off
    digitalWrite(ledPin, !LED_ON);
  }

When you verify, LED_ON will be replaced by the defined value. So the digitalWrites will contain LOW and !LOW (which equals HIGH).

You might also have something in setup that needs a similar modification.