#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)
/* 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;
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) {