-
Notifications
You must be signed in to change notification settings - Fork 0
/
Control_two_Servos.ino
71 lines (71 loc) · 1.17 KB
/
Control_two_Servos.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <avr/io.h>
#include <avr/interrupt.h>
#define setbit(x,y) (x |= y)
#define clearbit(x,y)(x &=~y)
#define bitn(p) (0x01 << (p))
#define checkbit(x,y) ((x) & (y))
int count, angle,angle1,count_angle,count_angle1;
int main(void)
{
DDRD = 0xFF;
TCNT1 =0x00;
OCR1A = 21;
TCCR1A = 0x00;
TCCR1B = 0x0A;
TIMSK1 =0x02;
SREG=0x80;
homeposition();
_delay_ms(2000);
while(1)
{
for (int i = 1; i <= 30; i++)
{
angle++;
angle1++;
convert();
}
_delay_ms(1000);
for (int j = 1; j <= 30; j++)
{
angle--;
angle1--;
convert();
}
_delay_ms(1000);
}
}
void convert()
{
count_angle = angle + 46;
count_angle1 = angle1 + 46;
_delay_us(5000);
}
void homeposition()
{
angle = 90;
angle1 = 90;
}
ISR (TIMER1_COMPA_vect)
{
count++;
if (count <= count_angle)
{
setbit(PORTD, bitn(4));
}
else if ((count > count_angle) && (count < 1818))
{
clearbit (PORTD,bitn(4));
}
else if (count >= 1818)
{
count=0;
}
if (count <= count_angle1)
{
setbit(PORTD, bitn(5));
}
else if ((count > count_angle) && (count < 1818))
{
clearbit (PORTD,bitn(5));
}
}