AssumingYou say your switch is on the taped cable at the bottom of the screen, it seems to be connected between pin 7 and ground. This being the case, it's going to pull the signal low when pressed+5v. I think Therefore you want to enable the internal pullupwill need a pull-down resistor on that pin, and change the sense of the pin 7.
const int led1 = 6;
const int enable1 = 7;
boolean led1_OnOff;
long now;
int minSecsBetweenUpdates = 1; // 1 seconds
long lastSend = -minSecsBetweenUpdates * 1000l;
void setup() {
led1_OnOff = false;
pinMode(enable1, INPUT_PULLUP);
pinMode(led1, OUTPUT);
}
void loop() {
now = millis();
if (now > (lastSend + minSecsBetweenUpdates * 1000l))
{
if(digitalRead(enable1) == LOW)
{
lastSend = now;
if(led1_OnOff == true)
{
led1_OnOff = false;
}
else
{
led1_OnOff = true;
}
}
// Wait for button to be released
while (digitalRead(enable1) == LOW) {}
}
if(led1_OnOff == true)
digitalWrite(led1, HIGH);
else
digitalWrite(led1, LOW);
}
NoteYou say that Majenko's method of waiting for the buttonsetting pin 7 to be released is non-blocking and arguably therefore more elegant, butan output works. However you are very likely to burn out the issue hereoutput like this. A pull-down resistor is identifying the problem rather than code review, hence I've made minimal changesway to your code. I'd recommend you clean it up as per Majenko's suggestiongo.