36 lines
690 B
Arduino
36 lines
690 B
Arduino
int ledPin = LED_BUILTIN;
|
|
int buttonPin = 2; // Button connected to D2 and GND
|
|
bool active = false;
|
|
|
|
void setup() {
|
|
pinMode(ledPin, OUTPUT);
|
|
pinMode(buttonPin, INPUT_PULLUP);
|
|
Serial.begin(9600);
|
|
Serial.println("Starting doorbell sensor");
|
|
}
|
|
|
|
void loop() {
|
|
int val = digitalRead(buttonPin);
|
|
|
|
if (val == LOW) {
|
|
delay(2); // catch flares
|
|
if (val == LOW && active == false) {
|
|
Serial.println("RING");
|
|
digitalWrite(ledPin, HIGH);
|
|
active = true;
|
|
delay(250);
|
|
}
|
|
else {
|
|
// Serial.println("flare");
|
|
}
|
|
}
|
|
else {
|
|
delay(2); // catch flares
|
|
if (val == HIGH) {
|
|
active = false;
|
|
digitalWrite(ledPin, LOW);
|
|
}
|
|
}
|
|
|
|
}
|