-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIMove.cpp
160 lines (135 loc) · 2.36 KB
/
IMove.cpp
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#ifndef __IMOVE_H__
#define __IMOVE_H__
#include "IMove.h"
IMove::IMove(int left_go, int left_back,
int right_go, int right_back)
{
left_motor_go = left_go;
left_motor_back = left_back;
right_motor_go = right_go;
right_motor_back = right_back;
};
void IMove::left_go(int PWM)
{
digitalWrite(left_motor_go, LOW);
digitalWrite(left_motor_back, HIGH);
analogWrite(left_motor_back, PWM);
};
void IMove::left_stop()
{
digitalWrite(left_motor_go, LOW);
digitalWrite(left_motor_back, LOW);
};
void IMove::left_back(int PWM)
{
digitalWrite(left_motor_go, HIGH);
digitalWrite(left_motor_back, LOW);
analogWrite(left_motor_go, PWM);
};
void IMove::right_go(int PWM)
{
digitalWrite(right_motor_go, HIGH);
digitalWrite(right_motor_back, LOW);
analogWrite(right_motor_go, PWM);
};
void IMove::right_stop()
{
digitalWrite(right_motor_go, LOW);
digitalWrite(right_motor_back, LOW);
};
void IMove::right_back(int PWM)
{
digitalWrite(right_motor_go, LOW);
digitalWrite(right_motor_back, HIGH);
analogWrite(right_motor_back, PWM);
};
void IMove::init()
{
pinMode(left_motor_go, OUTPUT);
pinMode(left_motor_back, OUTPUT);
pinMode(right_motor_go, OUTPUT);
pinMode(right_motor_back, OUTPUT);
};
void IMove::run(int PWM)
{
if(status!=RUN)
{
left_go();
right_go();
delay(firstsetp_time);
status = RUN;
}
left_go(PWM);
right_go(PWM);
};
void IMove::back(int PWM)
{
if(status!=BACK)
{
left_back();
right_back();
delay(firstsetp_time);
status = BACK;
}
left_back(PWM);
right_back(PWM);
};
//左电机不动,右电机前进
void IMove::left(int PWM)
{
if(status!=LEFT)
{
right_go();
left_stop();
delay(firstsetp_time);
status = LEFT;
}
right_go(PWM);
left_stop();
};
//右电机不动,左电机前进
void IMove::right(int PWM)
{
if(status!=RIGHT)
{
right_stop();
left_go();
delay(firstsetp_time);
status = RIGHT;
}
right_stop();
left_go(PWM);
};
//左电机后退,右电机前进
void IMove::spin_left(int PWM)
{
if(status!=LEFT)
{
left_back();
right_go();
delay(firstsetp_time);
status = LEFT;
}
left_back(PWM);
right_go(PWM);
};
//右电机后退,左电机前进
void IMove::spin_right(int PWM)
{
if(status!=RIGHT)
{
right_back();
left_go();
delay(firstsetp_time);
status = RIGHT;
}
right_back(PWM);
left_go(PWM);
};
void IMove::stop()
{
left_stop();
right_stop();
status = STOP;
};
#endif // __IMOVE_H__