const int knockSensor = 0; const int threshold = 80; int sensorReading = 0; bool state; bool previousState; void setup() { Serial.begin(9600); state = false; previousState = state; } void loop() { sensorReading = analogRead(knockSensor); interrupts(); if (sensorReading > threshold && !previousState) { state = !state; previousState = true; if (state) { Serial.println("Contact"); } else { Serial.println("Contact"); } } noInterrupts(); if (sensorReading < threshold) { previousState = false; } }