From b14055bcfaec276bf80c34b83e70597295f6c33e Mon Sep 17 00:00:00 2001 From: Philipp Matthias Schaefer Date: Sun, 2 Feb 2020 20:51:07 +0100 Subject: [PATCH] Simplify update_space_status --- arduino/door_status.ino | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/arduino/door_status.ino b/arduino/door_status.ino index a3a0963..461ee11 100644 --- a/arduino/door_status.ino +++ b/arduino/door_status.ino @@ -32,19 +32,10 @@ void print_status() { } void update_space_status() { - int pin_status = 0; - - pin_status = digitalRead(REED_SWITCH_INPUT_PIN); - - // pin check of the reed sensor and low pass filter - if (pin_status == 0){ - if (space_status > 0){ - space_status -= 1; - } - } else if (pin_status == 1){ - if (space_status < THRESHOLD){ - space_status += 1; - } + if(LOW == digitalRead(REED_SWITCH_INPUT_PIN)) { + space_status = max(0, space_status - 1); + } else { + space_status = min(THRESHOLD, space_status + 1); } }