bugfix flare catch
This commit is contained in:
@@ -1,33 +1,37 @@
|
|||||||
int ledPin = LED_BUILTIN;
|
int ledPin = LED_BUILTIN;
|
||||||
int buttonPin = 2; // Button connected to D2 and GND
|
int buttonPin = 2; // Button connected to D2 and GND
|
||||||
|
int flare_threshold = 30;
|
||||||
unsigned long lowTime = millis();
|
|
||||||
unsigned long highTime = millis();
|
|
||||||
unsigned long difference = 0;
|
|
||||||
bool active = false;
|
bool active = false;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
pinMode(ledPin, OUTPUT);
|
pinMode(ledPin, OUTPUT);
|
||||||
pinMode(buttonPin, INPUT_PULLUP);
|
pinMode(buttonPin, INPUT_PULLUP);
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
Serial.println("Starting button test");
|
Serial.println("Starting doorbell sensor");
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
int val = digitalRead(buttonPin);
|
int val = digitalRead(buttonPin);
|
||||||
|
|
||||||
if (val == LOW && active == false) {
|
if (val == LOW) {
|
||||||
lowTime = millis();
|
delay(flare_threshold); // catch flares
|
||||||
difference = lowTime - highTime;
|
val = digitalRead(buttonPin);
|
||||||
Serial.print("LOW ");
|
|
||||||
Serial.println(difference);
|
if (val == LOW && active == false) {
|
||||||
active = true;
|
Serial.println("RING");
|
||||||
|
digitalWrite(ledPin, HIGH);
|
||||||
|
active = true;
|
||||||
|
delay(250);
|
||||||
|
}
|
||||||
|
else if (val == HIGH) {
|
||||||
|
Serial.print("flare (<");
|
||||||
|
Serial.print(flare_threshold);
|
||||||
|
Serial.println(")");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (val == HIGH && active == true) {
|
else {
|
||||||
highTime = millis();
|
|
||||||
difference = highTime - lowTime;
|
|
||||||
Serial.print("HIGH ");
|
|
||||||
Serial.println(difference);
|
|
||||||
active = false;
|
active = false;
|
||||||
|
digitalWrite(ledPin, LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user