int LEDState = 0;
int LEDPin = 8;
int buttonPin = 12;
int buttonNew;
int buttonOld = 1; // input_pullup are normaly high
int dt = 100;
int buzzerPin = 7;
int i;
void setup() {
Serial.begin(9600);
pinMode(LEDPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
static bool doIt; // flag to inhibit/allow - initially false
// see if the button got presssed and fix the flag
delay(20); // very poor man's debounce: throttle the loop
buttonNew = digitalRead(buttonPin);
if (buttonOld != buttonNew) {
if (buttonNew)
doIt = !doIt; // toggle the flag on button action (release)
buttonOld = buttonNew;
}
// now either do or don't <whatever> based on the flag
static unsigned int counter; // just so we can differentiate the spam lines this produces
if (doIt) {
Serial.print(counter);
Serial.println(" do this stuff here!");
counter++;
}
}