If the button is active then the LED is off until the button is pressed.
If the LED is active the button is disabled and the LED is on.
There's clearly one more combination, as at boot up the button doesn't illuminate the LED. I've not however figured out that combination but I'm thinking an internal pull-up/drain setting on the GPIO. Maybe there is a relationship with pin #1; regardless, I could not get the LED to flash if the button was active.
I therefore went for this combination:
const int buttonPin = 16;
void button(bool enabled)
{
pinMode(buttonPin, OUTPUT);
digitalWrite(buttonPin, enabled ? HIGH : LOW);
if (enabled) pinMode(buttonPin, INPUT);
}
void flash()
{
for (int i = 0; i < 5; i++)
{
button(false); // Toggle button makes LED go on/off
delay(100);
button(true); // Toggle button makes LED go on/off
delay(100);
}
}
void setup()
{
button(true);
flash();
}
bool wait_for_release = false;
void loop()
{
if (digitalRead(buttonPin) == HIGH)
{
wait_for_release = true;
}
else if (wait_for_release)
{
wait_for_release = false;
flash();
}
}