diff options
| author | Sadeep Madurange <sadeep@asciimx.com> | 2024-11-03 12:36:54 +0800 |
|---|---|---|
| committer | Sadeep Madurange <sadeep@asciimx.com> | 2024-11-03 12:36:54 +0800 |
| commit | 92807aed3d3dc17fdf94d35d8b26c1d894aab9f2 (patch) | |
| tree | a2877f6983cebd51a74fa03aa08779af7833e4e0 /door_lock/main.c | |
| parent | d41e70ce3463f6b239da415c5d69773fce55f9e9 (diff) | |
| download | smart-home-92807aed3d3dc17fdf94d35d8b26c1d894aab9f2.tar.gz | |
Basic servo control.
Diffstat (limited to 'door_lock/main.c')
| -rw-r--r-- | door_lock/main.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/door_lock/main.c b/door_lock/main.c new file mode 100644 index 0000000..7308d35 --- /dev/null +++ b/door_lock/main.c @@ -0,0 +1,28 @@ +#include <avr/io.h> +#include <util/delay.h> + +int main(void) { + DDRB |= 1 << PINB1; // Set pin 9 on arduino to output + + /* 1. Set Fast PWM mode 14: set WGM11, WGM12, WGM13 to 1 */ + /* 3. Set pre-scaler of 8 */ + /* 4. Set Fast PWM non-inverting mode */ + TCCR1A |= (1 << WGM11) | (1 << COM1A1); + TCCR1B |= (1 << WGM12) | (1 << WGM13) | (1 << CS11); + + /* 2. Set ICR1 register: PWM period */ + ICR1 = 39999; + + /* Offset for correction */ + int offset = 800; + + /* 5. Set duty cycle */ + while(1) { + OCR1A = 3999 + offset; + _delay_ms(5000); + OCR1A = 1999 - offset; + _delay_ms(5000); + } + + return 0; +} |
