summaryrefslogtreecommitdiffstats
path: root/lock/util.c
diff options
context:
space:
mode:
authorSadeep Madurange <sadeep@asciimx.com>2025-05-05 11:51:40 +0800
committerSadeep Madurange <sadeep@asciimx.com>2025-05-05 11:51:40 +0800
commit605423d76e1f73c5a8590163b841c2db523626f7 (patch)
treec97b89849d8fbf5d6d542db889cfe35d2cc44fe5 /lock/util.c
parent96458bdb51704320216335f859bbd55e6594222f (diff)
downloadsmart-home-605423d76e1f73c5a8590163b841c2db523626f7.tar.gz
LEDs working.
Diffstat (limited to 'lock/util.c')
-rw-r--r--lock/util.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/lock/util.c b/lock/util.c
index ebcf9fe..5a22ef1 100644
--- a/lock/util.c
+++ b/lock/util.c
@@ -4,6 +4,12 @@
#include "util.h"
+#define LOCK_LED PC3
+#define UNLOCK_LED PC4
+#define BATLOW_LED PC5
+#define LED_DDR DDRC
+#define LED_PORT PORTC
+
int is_btn_pressed(uint8_t pin, uint8_t btn)
{
if (!((pin >> btn) & 0x01)) {
@@ -44,3 +50,40 @@ uint16_t getvcc(void)
ADCSRA &= ~(1 << ADEN);
return vcc;
}
+
+void led_init(void)
+{
+ LED_DDR |= (1 << LOCK_LED) | (1 << UNLOCK_LED);
+ LED_DDR |= (1 << BATLOW_LED);
+
+ LED_PORT &= ~(1 << LOCK_LED);
+ LED_PORT &= ~(1 << UNLOCK_LED);
+ LED_PORT &= ~(1 << BATLOW_LED);
+}
+
+void led_locked(void)
+{
+ LED_PORT |= (1 << LOCK_LED);
+ _delay_ms(70);
+ LED_PORT &= ~(1 << LOCK_LED);
+ _delay_ms(70);
+ LED_PORT |= (1 << LOCK_LED);
+ _delay_ms(70);
+ LED_PORT &= ~(1 << LOCK_LED);
+}
+
+void led_unlocked(void)
+{
+ LED_PORT |= (1 << UNLOCK_LED);
+ _delay_ms(70);
+ LED_PORT &= ~(1 << UNLOCK_LED);
+ _delay_ms(70);
+ LED_PORT |= (1 << UNLOCK_LED);
+ _delay_ms(70);
+ LED_PORT &= ~(1 << UNLOCK_LED);
+}
+
+void led_bat(void)
+{
+ LED_PORT ^= (1 << BATLOW_LED);
+}