fix LED and button management
authorOlivier Matz <zer0@droids-corp.org>
Sun, 14 Jul 2013 14:23:24 +0000 (16:23 +0200)
committerOlivier Matz <zer0@droids-corp.org>
Sun, 14 Jul 2013 14:23:24 +0000 (16:23 +0200)
main.c

diff --git a/main.c b/main.c
index 3bdb5d6..200b67c 100644 (file)
--- a/main.c
+++ b/main.c
 #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) {