// For https://forum.arduino.cc/t/push-button-hold-it-down-but-only-send-message-once/987854/27
const byte normPin = 3;
const byte buttonPin = 2;
const byte ledPin = LED_BUILTIN;
void your_function(){
static int j = 0;
Serial.print(j++);
for(int i = 0;i < 7; i++ ){
Serial.print(",");
Serial.print(i);
digitalWrite(ledPin,!digitalRead(ledPin));
delay(500);
}
Serial.println();
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(ledPin,OUTPUT);
// https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/
attachInterrupt(digitalPinToInterrupt(buttonPin), your_function, RISING);
}
void loop() {
static int lastButtonState;
int buttonState = digitalRead(normPin);
if (buttonState != lastButtonState) {
if (buttonState == HIGH) { // rising edge
your_function();
}
// Delay a little bit to avoid bouncing
//delay(50); // already debounced by the time used by other functions
}
// save the current state as the last state, for next time through the loop
lastButtonState = buttonState;
}
// https://www.arduino.cc/reference/en/language/variables/variable-scope-qualifiers/volatile/