summaryrefslogtreecommitdiffstats
path: root/door_lock/main.c
diff options
context:
space:
mode:
authorSadeep Madurange <sadeep@asciimx.com>2024-11-05 16:51:55 +0800
committerSadeep Madurange <sadeep@asciimx.com>2024-11-05 16:51:55 +0800
commitea30b232f637282dfa87ded8c7da7596430f1de4 (patch)
tree7ac2c53bda71e4b308e2cfdb8b27f1edd9fb4d87 /door_lock/main.c
parentdc7edbe1adda2b620d1e106c64d06890d2f29dfe (diff)
downloadsmart-home-ea30b232f637282dfa87ded8c7da7596430f1de4.tar.gz
Function to check btn press.
Diffstat (limited to 'door_lock/main.c')
-rw-r--r--door_lock/main.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/door_lock/main.c b/door_lock/main.c
index e02849c..fa8b046 100644
--- a/door_lock/main.c
+++ b/door_lock/main.c
@@ -1,6 +1,8 @@
#include <stddef.h>
+
#include <avr/io.h>
#include <avr/interrupt.h>
+#include <util/delay.h>
#define PWM_MIN 1200
#define PWM_MID 3000
@@ -22,12 +24,21 @@ static inline void servo_init(void)
PORTD |= (1 << LOCK_BTN) | (1 << UNLOCK_BTN);
}
+static inline void int0_init(void)
+{
+ EIMSK |= (1 << INT0);
+ EICRA |= (1 << ISC00);
+}
+
+static inline uint8_t is_btn_pressed(uint8_t btn)
+{
+ return !((PIND >> btn) & 0x01);
+}
+
int main(void)
{
servo_init();
-
- EICRA |= (1 << ISC00);
- EIMSK |= (1 << INT0);
+ int0_init();
sei();
@@ -37,11 +48,11 @@ int main(void)
return 0;
}
-ISR (INT0_vect)
+ISR(INT0_vect)
{
- if (!((PIND >> LOCK_BTN) & 0x01))
+ if (is_btn_pressed(LOCK_BTN))
OCR1A = PWM_MID;
- if (!((PIND >> UNLOCK_BTN) & 0x01))
+ if (is_btn_pressed(UNLOCK_BTN))
OCR1A = PWM_MIN;
}