summaryrefslogtreecommitdiffstats
path: root/door_lock
diff options
context:
space:
mode:
Diffstat (limited to 'door_lock')
-rw-r--r--door_lock/main.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/door_lock/main.c b/door_lock/main.c
index 9774bab..36c4a37 100644
--- a/door_lock/main.c
+++ b/door_lock/main.c
@@ -1,8 +1,6 @@
#include <stddef.h>
#include <avr/io.h>
-#include <util/delay.h>
-
-#include "serial.h"
+#include <avr/interrupt.h>
#define PWM_MIN 1200
#define PWM_MID 3000
@@ -17,28 +15,33 @@ static inline void servo_init(void)
DDRB |= 1 << SERVO_PIN;
TCCR1A |= (1 << WGM11) | (1 << COM1A1);
TCCR1B |= (1 << WGM12) | (1 << WGM13) | (1 << CS11);
+
ICR1 = 40000;
DDRD &= ~((1 << LOCK_BTN) | (1 << UNLOCK_BTN));
PORTD |= (1 << LOCK_BTN) | (1 << UNLOCK_BTN);
}
-static inline uint8_t is_btn_pressed(uint8_t btn)
-{
- return !((PIND >> btn) & 0x01);
-}
-
int main(void)
{
servo_init();
- for(;;) {
- if (is_btn_pressed(LOCK_BTN))
- OCR1A = PWM_MID;
+ EICRA |= (1 << ISC00);
+ EIMSK |= (1 << INT0);
- if (is_btn_pressed(UNLOCK_BTN))
- OCR1A = PWM_MIN;
- }
+ sei();
+
+ for(;;)
+ ;
return 0;
}
+
+ISR (INT0_vect)
+{
+ if ((PIND & (1 << LOCK_BTN)))
+ OCR1A = PWM_MID;
+
+ if ((PIND & (1 << UNLOCK_BTN)))
+ OCR1A = PWM_MIN;
+}