Files
smart-home/klingel_sender_nano_serial/klingel_sender_nano_serial.ino
T
2020-09-18 08:33:26 +02:00

34 lines
771 B
Arduino

int ledPin = LED_BUILTIN;
int buttonPin = 2; // Button connected to D2 and GND
unsigned long lowTime = millis();
unsigned long highTime = millis();
unsigned long difference = 0;
bool active = false;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
Serial.begin(9600);
Serial.println("Starting button test");
}
void loop() {
int val = digitalRead(buttonPin);
if (val == LOW && active == false) {
lowTime = millis();
difference = lowTime - highTime;
Serial.print("LOW ");
Serial.println(difference);
active = true;
}
else if (val == HIGH && active == true) {
highTime = millis();
difference = highTime - lowTime;
Serial.print("HIGH ");
Serial.println(difference);
active = false;
}
}