Last active
August 29, 2015 14:21
-
-
Save kkmonster/5db453ed62704f246af1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
kkmonster cmmc : internal clock 1 Mhz | |
*/ | |
#include <avr/interrupt.h> | |
#include <util/delay.h> | |
#define servo_pin 0 | |
volatile int servo = 100; | |
void setup() | |
{ | |
pinMode(servo_pin, OUTPUT); | |
TCCR0A |=(1<<WGM01); //CTC mode, set OC0A on match //Clear Timer on Compare Match (Auto Reload) | |
TIMSK |= (1<<OCIE0A); //CTC Interrupt enable | |
sei(); // enble interrupt | |
} | |
void loop() | |
{ | |
servo = ??? | |
.... | |
} | |
ISR(TIMER0_COMPA_vect) | |
{ | |
digitalWrite(servo_pin, HIGH); | |
delay_us(50); // calibation for 500us | |
delay_us(servo); // 200 for delay 1500us | |
digitalWrite(servo_pin, LOW); | |
} | |
void delay_us(int temp) | |
{ | |
while(temp > 0) | |
{ | |
_delay_us(1); | |
temp--; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment