38 lines
785 B
Arduino
38 lines
785 B
Arduino
int ledPin = LED_BUILTIN;
|
|
int buttonPin = 2; // Button connected to D2 and GND
|
|
int flare_threshold = 20;
|
|
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(flare_threshold); // catch flares
|
|
val = digitalRead(buttonPin);
|
|
|
|
if (val == LOW && active == false) {
|
|
Serial.println("RING");
|
|
digitalWrite(ledPin, HIGH);
|
|
active = true;
|
|
delay(250);
|
|
}
|
|
else if (val == HIGH) {
|
|
Serial.print("flare (<");
|
|
Serial.print(flare_threshold);
|
|
Serial.println(")");
|
|
}
|
|
}
|
|
else {
|
|
active = false;
|
|
digitalWrite(ledPin, LOW);
|
|
}
|
|
|
|
}
|