Skip to content

Instantly share code, notes, and snippets.

@cmoz
Created March 30, 2022 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmoz/a68e80b5a18aa6e44422104d57e237d1 to your computer and use it in GitHub Desktop.
Save cmoz/a68e80b5a18aa6e44422104d57e237d1 to your computer and use it in GitHub Desktop.
#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