diff options
| author | Sadeep Madurange <sadeep@asciimx.com> | 2025-05-05 11:51:40 +0800 |
|---|---|---|
| committer | Sadeep Madurange <sadeep@asciimx.com> | 2025-05-05 11:51:40 +0800 |
| commit | 605423d76e1f73c5a8590163b841c2db523626f7 (patch) | |
| tree | c97b89849d8fbf5d6d542db889cfe35d2cc44fe5 /lock/util.c | |
| parent | 96458bdb51704320216335f859bbd55e6594222f (diff) | |
| download | smart-home-605423d76e1f73c5a8590163b841c2db523626f7.tar.gz | |
LEDs working.
Diffstat (limited to 'lock/util.c')
| -rw-r--r-- | lock/util.c | 43 |
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); +} |
