klingel_sender_nano_serial.ino: Zusätzlicher Button für Garagentor
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
/* Klingel-Sensor auf Arduino Nano ATmega168
|
/* Klingel-Sensor auf Arduino Nano ATmega168 plus zweiter Button für das Garagentor
|
||||||
|
* Die Buttons sind über Optokoppler mit dem Arduino verbunden,
|
||||||
|
* um den Spannungsabfall über die lange Leitung auszugleichen.
|
||||||
*
|
*
|
||||||
* https://www.arduino.cc/en/Tutorial/BuiltInExamples/Button
|
* https://www.arduino.cc/en/Tutorial/BuiltInExamples/Button
|
||||||
* https://docs.arduino.cc/tutorials/generic/digital-input-pullup/
|
* https://docs.arduino.cc/tutorials/generic/digital-input-pullup/
|
||||||
@@ -6,7 +8,8 @@
|
|||||||
|
|
||||||
|
|
||||||
const int ledPin = LED_BUILTIN;
|
const int ledPin = LED_BUILTIN;
|
||||||
const int buttonPin = 2; // Button connected to D2
|
const int doorbellButtonPin = 2; // Button connected to D2
|
||||||
|
const int buttonPin = 4; // Button connected to D4
|
||||||
const int flare_threshold = 200;
|
const int flare_threshold = 200;
|
||||||
const int ring_delay = 250;
|
const int ring_delay = 250;
|
||||||
|
|
||||||
@@ -16,6 +19,7 @@ bool active = false;
|
|||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
pinMode(ledPin, OUTPUT);
|
pinMode(ledPin, OUTPUT);
|
||||||
|
pinMode(doorbellButtonPin, INPUT_PULLUP);
|
||||||
pinMode(buttonPin, INPUT_PULLUP);
|
pinMode(buttonPin, INPUT_PULLUP);
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
Serial.println("Doorbell sensor");
|
Serial.println("Doorbell sensor");
|
||||||
@@ -23,28 +27,50 @@ void setup() {
|
|||||||
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
int val = digitalRead(buttonPin);
|
int val = digitalRead(doorbellButtonPin);
|
||||||
|
|
||||||
|
if (val == LOW) {
|
||||||
|
delay(flare_threshold); // catch flares
|
||||||
|
val = digitalRead(doorbellButtonPin);
|
||||||
|
|
||||||
|
if (val == LOW && active == false) {
|
||||||
|
Serial.println("RING");
|
||||||
|
active = true;
|
||||||
|
digitalWrite(ledPin, HIGH);
|
||||||
|
delay(ring_delay);
|
||||||
|
}
|
||||||
|
else if (val == HIGH) {
|
||||||
|
Serial.print("flare (< ");
|
||||||
|
Serial.print(flare_threshold);
|
||||||
|
Serial.println(" ms)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
active = false;
|
||||||
|
digitalWrite(ledPin, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
val = digitalRead(buttonPin);
|
||||||
|
|
||||||
if (val == LOW) {
|
if (val == LOW) {
|
||||||
delay(flare_threshold); // catch flares
|
delay(flare_threshold); // catch flares
|
||||||
val = digitalRead(buttonPin);
|
val = digitalRead(buttonPin);
|
||||||
|
|
||||||
if (val == LOW && active == false) {
|
if (val == LOW && active == false) {
|
||||||
Serial.println("RING");
|
Serial.println("CLICK");
|
||||||
digitalWrite(ledPin, HIGH);
|
|
||||||
active = true;
|
active = true;
|
||||||
|
digitalWrite(ledPin, HIGH);
|
||||||
delay(ring_delay);
|
delay(ring_delay);
|
||||||
}
|
}
|
||||||
else if (val == HIGH) {
|
else if (val == HIGH) {
|
||||||
Serial.print("flare (<");
|
Serial.print("flare (< ");
|
||||||
Serial.print(flare_threshold);
|
Serial.print(flare_threshold);
|
||||||
Serial.println(")");
|
Serial.println(" ms)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
digitalWrite(ledPin, LOW);
|
|
||||||
active = false;
|
active = false;
|
||||||
|
digitalWrite(ledPin, LOW);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user