-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMeMegaPiDCMotorTest.ino
More file actions
135 lines (116 loc) · 2.5 KB
/
MeMegaPiDCMotorTest.ino
File metadata and controls
135 lines (116 loc) · 2.5 KB
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
#include <MeMegaPi.h>
MeMegaPiDCMotor motor1(PORT2B);
MeMegaPiDCMotor motor2(PORT1B);
MeMegaPiDCMotor motor3(PORT3B);
MeMegaPiDCMotor motor4(PORT4B); // Motor at slot4
uint8_t motorSpeed = 200;
char val;
int card_length_to_ms(float card_length) {
return 625*card_length;
}
void setup()
{
Serial.begin(9600);
Serial.println("<Arduino is ready>");
}
void loop()
{
val = Serial.read();
if (val == 'w') {
motor2.run(motorSpeed);
motor1.run(-motorSpeed);
delay(1000);
motor2.stop();
motor1.stop();
}
else if (val == 's') {
motor2.run(-motorSpeed);
motor1.run(motorSpeed);
delay(1000);
motor2.stop();
motor1.stop();
}
else if (val == 'a') {
motor2.run(-motorSpeed);
motor1.run(-motorSpeed);
delay(1000);
motor2.stop();
motor1.stop();
}
else if (val == 'd') {
motor2.run(motorSpeed);
motor1.run(motorSpeed);
delay(1000);
motor2.stop();
motor1.stop();
}
else if (val == 'q') {
motor3.run(-motorSpeed);
delay(500);
motor3.stop();
motor4.run(-200);
delay(5000);
motor4.stop();
}
else if (val == 'e') {
motor3.run(motorSpeed);
delay(500);
motor3.stop();
motor4.run(200);
delay(5000);
motor4.stop();
}
else if (val == 'p') {
motor2.run(motorSpeed);
motor1.run(-motorSpeed);
delay(1000);
motor2.stop();
motor1.stop();
motor3.run(-motorSpeed);
//delay(card_length_to_ms())
}
else if (val == 't') {
align();
motor3.run(-motorSpeed);
delay(1200);
motor3.stop();
motor2.run(motorSpeed);
motor1.run(-motorSpeed);
delay(1000);
motor2.stop();
motor1.stop();
motor4.run(motorSpeed);
delay(500);
motor4.stop();
motor3.run(motorSpeed);
delay(1000);
motor3.stop();
// motor4.stop();
// motor3.run(-motorSpeed);
// delay(500);
// motor3.stop();
// motor4.run(motorSpeed);
// delay(1000);
// motor4.stop();
// motor3.run(motorSpeed);
// delay(1000);
// motor3.stop();
}
else if (val == 'i') {
motor3.run(motorSpeed);
delay(2000);
motor3.stop();
motor4.run(-motorSpeed);
delay(1500)
motor4.stop();
}
}
void align()
{
while(imageNotCentred){
//keep spinning
if(centred){
break;
}
}
}