From: Bernhard Tittelbach Date: Wed, 23 Nov 2011 21:30:22 +0000 (+0000) Subject: software ajar sensor low pass X-Git-Url: https://git.realraum.at/?a=commitdiff_plain;h=5465893d6d77bfb69fb7846b12401c949f317b30;p=svn42.git software ajar sensor low pass --- diff --git a/firmware/tuer.pde b/firmware/tuer.pde index 3813e00..5466ba7 100644 --- a/firmware/tuer.pde +++ b/firmware/tuer.pde @@ -82,12 +82,21 @@ boolean is_closed() //**********// +#define AJAR_LOW_PASS_TAU 200 +byte ajar_low_pass_counter = 0; +byte ajar_low_pass_last_value = ajar_last_state; byte get_ajar_status() { - if(digitalRead(AJAR_PIN) == LOW) - return SHUT; - - return AJAR; + b = ( (digitalRead(AJAR_PIN) == LOW)? SHUT : AJAR ); + ajar_low_pass_counter = ( (b == ajar_low_pass_last_value)? ajar_low_pass_counter + 1 : 0 ); + ajar_low_pass_last_value = b; + if (ajar_low_pass_counter >= AJAR_LOW_PASS_TAU) + { + ajar_low_pass_counter = 0; + return b; + } + else + return ajar_last_state; } void init_ajar()