Skip to content

Instantly share code, notes, and snippets.

@surinoel
Created July 9, 2019 03:58
Show Gist options
  • Save surinoel/f6ff3d3982f91e1b230b1afc79f5571c to your computer and use it in GitHub Desktop.
Save surinoel/f6ff3d3982f91e1b230b1afc79f5571c to your computer and use it in GitHub Desktop.
int pinHit = 2;
int pinLed = 13;
int ledStatus = LOW;
int count = 0;
volatile int flag = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(pinHit, INPUT);
pinMode(pinLed, OUTPUT);
attachInterrupt(0, hitISR, FALLING);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.print("HIT : ");
Serial.println(count);
flag = 0;
digitalWrite(pinLed, ledStatus);
delay(500);
}
void hitISR(void) {
if(flag == 0) {
count++;
flag = 1;
ledStatus = !ledStatus;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment