Created
March 20, 2016 11:57
-
-
Save ViliusKraujutis/2aa62165bf5ee2f7b179 to your computer and use it in GitHub Desktop.
does not detect knocks on table, but senses shocks while holding in hand
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
const int ledPin = 31; // define ledPin Interface | |
const int shockPin = 30; // define the percussion Sensor Interface | |
int val; // define numeric variables val | |
long lastKnockTimestamp = 0; | |
int knockTimeout = 2000; | |
void setup () { | |
Serial.begin(9600); | |
pinMode (ledPin, OUTPUT) ; // define ledPin as output interface | |
pinMode (shockPin, INPUT) ; // define knock sensor output interface | |
Serial.println("Running..."); | |
} | |
void loop () { | |
val = digitalRead (shockPin) ; // read digital interface is assigned a value of 3 val | |
if (val == LOW) { | |
lastKnockTimestamp = millis(); | |
} | |
if (millis() - lastKnockTimestamp < knockTimeout) { | |
digitalWrite (ledPin, HIGH); | |
} else { | |
digitalWrite (ledPin, LOW); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment