-
Notifications
You must be signed in to change notification settings - Fork 0
/
Slide_left.ino
124 lines (118 loc) · 2.37 KB
/
Slide_left.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include <avr/io.h>
#include <avr/interrupt.h>
#include <LCD.h>
#define clearbit(x,y)(x &=~y)
#define setbit(x,y) (x |= y)
#define checkbit(x,y) ((x) & (y))
#define bitn(p) (0x01 << (p))
LCD lcd;
int count=0;
int right_hip,count_angle, right_foot, count_angle1,
left_hip,count_angle2, left_foot, count_angle3,
left_hand, count_angle4,right_hand,count_angle5;
int main()
{
DDRD = 0xFF;
TCNT1 = 0x00;
OCR1A = 21;
TCCR1A = 0x00;
TCCR1B = 0x0A;
TIMSK1 = 0X02;
SREG = 0x80;
home_position();
convert();
while(1)
{
for (right_foot = 90; right_foot <= 130; right_foot++)
{
convert();
}
for (left_foot = 90; left_foot >= 70; left_foot--)
{
convert();
}
for (right_foot = 130; right_foot >= 90; right_foot--)
{
convert();
}
for (left_foot = 70; left_foot <= 90; left_foot++)
{
convert();
}
}
}
void convert()
{
count_angle = right_hip + 46;
count_angle1 = right_foot + 46;
count_angle2 = left_hip + 46;
count_angle3 = left_foot + 46;
count_angle4 = left_hand + 46;
count_angle5 = right_hand + 46;
_delay_us(1200);
}
void home_position()
{
right_hip = 90;
right_foot = 90;
left_hip = 90;
left_foot = 90;
left_hand = 140;
right_hand = 40;
}
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));
}
if (count <= count_angle2)
{
setbit(PORTD, bitn(6));
}
else if ((count > count_angle2) && (count < 1818))
{
clearbit (PORTD,bitn(6));
}
if (count <= count_angle3)
{
setbit(PORTD, bitn(7));
}
else if ((count > count_angle3) && (count < 1818))
{
clearbit (PORTD,bitn(7));
}
if (count <= count_angle4)
{
setbit(PORTD, bitn(3));
}
else if ((count > count_angle4) && (count < 1818))
{
clearbit (PORTD,bitn(3));
}
if (count <= count_angle5)
{
setbit(PORTD, bitn(2));
}
else if ((count > count_angle5) && (count < 1818))
{
clearbit (PORTD,bitn(2));
}
}