Created
October 22, 2021 12:07
-
-
Save jenschr/dd539db1caca27e2032d2512b35f58d9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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