Created
March 30, 2022 12:31
-
-
Save cmoz/a68e80b5a18aa6e44422104d57e237d1 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
#define sensorPin 7 | |
int ledPin = 2; | |
unsigned long lastEvent = 0; | |
void setup() { | |
pinMode(sensorPin, INPUT); | |
pinMode(ledPin, OUTPUT); | |
Serial.begin(9600); | |
} | |
void loop() { | |
int sensorData = digitalRead(sensorPin); | |
if (sensorData == LOW) { | |
if (millis() - lastEvent > 25) { | |
Serial.println("Clap detected!"); | |
digitalWrite(ledPin,HIGH); | |
delay(100); | |
digitalWrite(ledPin, LOW); | |
} | |
lastEvent = millis(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment