Klingel-Sensor mit Arduino Nano und Python
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user