Skip to content

Instantly share code, notes, and snippets.

@jenschr
Created Oct 22, 2021
Embed
What would you like to do?
int lastVal = 0;
long lastKnock = 0;
void setup() {
Serial.begin( 9600 );
}
void loop() {
int readVal = analogRead( A2 );
if( readVal > lastVal+5 ){
int knockDiff = abs(readVal)-lastVal;
long nowTime = millis();
int diff = nowTime - lastKnock;
if( lastKnock != 0 && diff > 20 && diff < 2000 ){
Serial.print(knockDiff);
Serial.print(":");
if( diff > 300 ){
Serial.println( "knock" );
} else {
Serial.println( "doubleknock" );
}
}
lastKnock = nowTime;
}
lastVal = abs( readVal );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment