#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;
TCCR0B = (1 << CS01); /* clk/8 = 1Mhz */
while (1) {
+ /* 4 Khz */
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 at 500 Hz */
+ /* radio duty cycle is 500/4000 */
if (time_period < 500) {
TX_ENABLE();
+ /* at 500 Hz */
if (time_period & 4)
TX_ON();
else
/* filter button */
button = 0;
- if (BUTTON_IS_PRESSED() && button_filter < 10)
+ if (BUTTON_IS_PRESSED() && button_filter < 10) {
button_filter++;
- else if (BUTTON_IS_PRESSED() && button_filter == 10)
- button = 1;
+ if (button_filter == 10)
+ button = 1;
+ }
else if (!BUTTON_IS_PRESSED())
button_filter = 0;