X-Git-Url: https://git.realraum.at/?a=blobdiff_plain;f=firmware%2Ftuer.pde;h=6c966a25b5d35390b440966b3dfe8485ce11a8e5;hb=fdbf905e071e97b4079ff0a0ba7029135b234219;hp=1808c883ee888c4ca7943b26e0c39d5d2ce54a27;hpb=2099456b39e30a6baa1e31cdd2be5c1f26b5faeb;p=svn42.git diff --git a/firmware/tuer.pde b/firmware/tuer.pde index 1808c88..6c966a2 100644 --- a/firmware/tuer.pde +++ b/firmware/tuer.pde @@ -22,6 +22,13 @@ byte next_led = 0; #define MANUAL_OPEN_PIN 12 // keys for manual open and close #define MANUAL_CLOSE_PIN 13 // +#define DEBOUNCE_DELAY 6250 // * 16us = 100ms +#define DEBOUNCE_IDLE 0 // currently no debouncing +#define DEBOUNCE_OPEN 1 // debouncing open key +#define DEBOUNCE_CLOSE 2 // debouncing close key +#define DEBOUNCE_FINISHED 4 // debouncing finished +byte debounce_state; +int debounce_cnt = 0; #define IDLE 0 // close and open may be called #define OPENING 1 // opening, only 's' command is allowed @@ -31,6 +38,7 @@ byte next_led = 0; #define CMD_OPEN 'o' #define CMD_CLOSE 'c' +#define CMD_TOGGLE 't' #define CMD_STATUS 's' #define CMD_RESET 'r' @@ -76,9 +84,12 @@ void init_manual() pinMode(MANUAL_CLOSE_PIN, INPUT); // set pin to input digitalWrite(MANUAL_CLOSE_PIN, HIGH); // turn on pullup resistors + + debounce_state = DEBOUNCE_IDLE; + debounce_cnt = DEBOUNCE_DELAY; } -boolean manual_open() +boolean manual_open_pressed() { if(digitalRead(MANUAL_OPEN_PIN)) return false; @@ -86,7 +97,7 @@ boolean manual_open() return true; } -boolean manual_close() +boolean manual_close_pressed() { if(digitalRead(MANUAL_CLOSE_PIN)) return false; @@ -94,6 +105,92 @@ boolean manual_close() return true; } +void start_debounce_timer() // this breaks millis() function, but who cares +{ + debounce_cnt = DEBOUNCE_DELAY; + + TCCR0A = 0; // no prescaler, WGM = 0 (normal) + TCCR0B = 1< 16us @ 16 MHz + TCNT0 = 0; // reseting timer + TIMSK0 = 1<