From 92807aed3d3dc17fdf94d35d8b26c1d894aab9f2 Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Sun, 3 Nov 2024 12:36:54 +0800 Subject: Basic servo control. --- door_lock/main.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 door_lock/main.c (limited to 'door_lock/main.c') 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 +#include + +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; +} -- cgit v1.2.3