From: Olivier Matz Date: Sun, 14 Jul 2013 14:23:24 +0000 (+0200) Subject: fix LED and button management X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=e611a4d65868e5d49ab42d8683462cff77cc1147;p=beacon-tx-433.git fix LED and button management --- diff --git a/main.c b/main.c index 3bdb5d6..200b67c 100644 --- a/main.c +++ b/main.c @@ -32,7 +32,12 @@ #define BUZZER_ON() PORTB |= _BV(BUZZER_BIT) #define BUZZER_OFF() PORTB &= (~_BV(BUZZER_BIT)) -#define BUTTON_IS_PRESSED() 0 +#define BUTTON_BIT 3 +#define BUTTON_IS_PRESSED() (!(PINB & _BV(BUTTON_BIT))) + +#define LED_BIT 4 +#define LED_ON() PORTB |= _BV(LED_BIT) +#define LED_OFF() PORTB &= (~_BV(LED_BIT)) /* wait new period: timer unit is us: 250 -> 4 khz */ static void wait_period(void) @@ -58,7 +63,10 @@ int main(void) /* PORTB TX/DATA out*/ DDRB |= (1 << TX_ENABLE_BIT) | (1 << TX_BIT) | + (1 << LED_BIT) | (1 << BUZZER_BIT); + /* pull up */ + PORTB |= (1 << BUTTON_BIT); /* init timer */ TCCR0A = 0; @@ -69,14 +77,20 @@ int main(void) wait_period(); /* buzzer at 2 Khz after 10mns if not always on */ - if (always_on || time_second > 600) { - if ((time_period & 1) && (time_period < 500)) + if (always_on || time_second > 60) { + LED_OFF(); + /* every 2 secs */ + if (((time_second & 1) == 0) && + (time_period & 1) && + (time_period < 500)) BUZZER_ON(); else BUZZER_OFF(); } - else + else { + LED_ON(); BUZZER_OFF(); + } /* radio duty cycle is 500/4000 */ if (time_period < 500) {