Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit bb521ae

Browse files
Demo 2018-06-07 (Work)
1 parent c0ceeba commit bb521ae

File tree

1 file changed

+36
-15
lines changed

1 file changed

+36
-15
lines changed

arduino_control/arduino_control.ino

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// constants
22
#define NUMBER_OF_MOTORS 2
33
#define UP_SPEED 295
4-
#define DOWN_SPEED 270
4+
#define DOWN_SPEED 265
55
#define STOP_SPEED 0
66

77
// libraries
@@ -30,10 +30,7 @@ int sensor_value1[NUMBER_OF_MOTORS];
3030
int sensor_value2[NUMBER_OF_MOTORS];
3131
int rotation_int[NUMBER_OF_MOTORS];
3232
String rotation_direction[NUMBER_OF_MOTORS];
33-
34-
// motor pins
35-
int m1_sensor_pin = A0;
36-
int m2_sensor_pin = A0;
33+
int sensor_pin[] = {A0, A2};
3734

3835
String m1_rotation = "";
3936
String m2_rotation = "";
@@ -49,6 +46,9 @@ void setup() {
4946
rotation_direction[i] = "";
5047
}
5148

49+
pinMode(14, INPUT);
50+
pinMode(15, INPUT);
51+
5252
// setup serial monitor
5353
Serial.begin(9600);
5454

@@ -123,41 +123,62 @@ void processData() {
123123
Serial.println(recievedString);
124124

125125
for (int i=0; i<NUMBER_OF_MOTORS; i++) {
126-
if (rotation_direction[0] == "Up") {
126+
if (rotation_direction[i] == "Up") {
127127
upMotor(i);
128128
}
129-
else if (rotation_direction[0] == "Down") {
129+
else if (rotation_direction[i] == "Down") {
130130
downMotor(i);
131131
}
132132

133-
else if (rotation_direction[0] == "None"){
133+
else if (rotation_direction[i] == "None"){
134134
stopMotor(i);
135135
}
136136
else
137137
{
138+
// TODO: make this exit the program
138139
Serial.println("<");
139140
Serial.print("Arduino: ");
140141
Serial.println("Invalid Input!");
141142
}
143+
142144
}
143-
144145
////////////////
145-
rotation_int[1] = 0;
146+
//rotation_int[1] = 0;
146147
///////////////
148+
147149
while (1) {
148150
int count = 0;
151+
149152
for (int i=0; i<NUMBER_OF_MOTORS; i++) {
150-
count = count + rotation_int[i];
153+
count = count + rotation_int[i];
154+
//Serial.print("Motor: ");
155+
//Serial.println(i);
156+
//Serial.print("Rotations: ");
157+
//Serial.println(rotation_int[i]);
151158
}
152-
Serial.println(count);
153-
if (count == 0) {
159+
160+
if (count <= 0) {
154161
break;
155162
}
163+
156164
for (int i=0; i<NUMBER_OF_MOTORS; i++) {
165+
if (rotation_int[i] == 0) {
166+
stopMotor(i);
167+
}
157168
readValues(i);
169+
158170
if (sensor_value1[i] < 500 && sensor_value2[i] > 500){
159171
rotation_int[i] = rotation_int[i] - 1;
172+
//Serial.print("Sensor ");
173+
//Serial.print(i);
174+
//Serial.print(" Value: ");
175+
//Serial.println(sensor_value2[i]);
176+
if (rotation_int[i] < 0) {
177+
rotation_int[i] = 0;
178+
}
160179
}
180+
}
181+
for (int i=0; i<NUMBER_OF_MOTORS; i++) {
161182
if (rotation_int[i] == 0) {
162183
stopMotor(i);
163184
}
@@ -177,8 +198,8 @@ void showNewData() {
177198
}
178199

179200
void readValues(int motor_number) {
180-
sensor_value1[0] = sensor_value2[0];
181-
sensor_value2[0] = analogRead(m1_sensor_pin);
201+
sensor_value1[motor_number] = sensor_value2[motor_number];
202+
sensor_value2[motor_number] = analogRead(sensor_pin[motor_number]);
182203
}
183204

184205
String getValue(String data, char separator, int index)

0 commit comments

Comments
 (0)