@@ -121,69 +121,51 @@ void processData() {
121
121
Serial.println (" <" );
122
122
Serial.print (" RevievedString: " );
123
123
Serial.println (recievedString);
124
- Serial.println (" Number of Rotations: " );
125
- Serial.print (" m1: " );
126
- Serial.println (m1_rotation);
127
- Serial.print (" m2: " );
128
- Serial.println (m2_rotation);
129
-
130
-
131
- // while all motors aren't ready
132
-
133
-
134
124
135
- if (rotation_direction[ 0 ] == " Up " ) {
136
- Serial. println ( " < " );
137
- Serial. print ( " Arduino: " );
138
- Serial. println ( " Moving Up! " );
139
- upMotor ( 0 );
140
- while ( 1 ) {
141
- readValues ();
142
- Serial. println (sensor_value2[ 0 ]);
143
- if (sensor_value1 [0 ] < 500 && sensor_value2[ 0 ] > 500 ){
144
- rotation_int[ 0 ] = rotation_int[ 0 ] - 1 ;
145
- }
146
-
147
- if (rotation_int[ 0 ] == 0 ) {
148
- break ;
149
- }
150
- delay ( 500 );
125
+ for ( int i= 0 ; i<NUMBER_OF_MOTORS; i++ ) {
126
+ if (rotation_direction[ 0 ] == " Up " ) {
127
+ upMotor (i );
128
+ }
129
+ else if (rotation_direction[ 0 ] == " Down " ) {
130
+ downMotor (i);
131
+ }
132
+
133
+ else if (rotation_direction [0 ] == " None " ){
134
+ stopMotor (i) ;
135
+ }
136
+ else
137
+ {
138
+ Serial. println ( " < " );
139
+ Serial. print ( " Arduino: " );
140
+ Serial. println ( " Invalid Input! " );
151
141
}
152
- stopMotor (0 );
153
142
}
154
- else if (rotation_direction[0 ] == " Down" ) {
155
- Serial.println (" <" );
156
- Serial.print (" Arduino: " );
157
- Serial.println (" Moving Down!" );
158
- downMotor (0 );
159
- while (1 ) {
160
- readValues ();
161
- Serial.println (sensor_value2[0 ]);
162
- if (sensor_value1[0 ] < 500 && sensor_value2[0 ] > 500 ){
163
- rotation_int[0 ] = rotation_int[0 ] - 1 ;
143
+
144
+ // //////////////
145
+ rotation_int[1 ] = 0 ;
146
+ // /////////////
147
+ while (1 ) {
148
+ int count = 0 ;
149
+ for (int i=0 ; i<NUMBER_OF_MOTORS; i++) {
150
+ count = count + rotation_int[i];
151
+ }
152
+ Serial.println (count);
153
+ if (count == 0 ) {
154
+ break ;
155
+ }
156
+ for (int i=0 ; i<NUMBER_OF_MOTORS; i++) {
157
+ readValues (i);
158
+ if (sensor_value1[i] < 500 && sensor_value2[i] > 500 ){
159
+ rotation_int[i] = rotation_int[i] - 1 ;
164
160
}
165
-
166
- if (rotation_int[0 ] == 0 ){
167
- break ;
161
+ if (rotation_int[i] == 0 ) {
162
+ stopMotor (i);
168
163
}
169
- delay (500 );
170
164
}
171
- stopMotor (0 );
172
- }
173
-
174
- else if (rotation_direction[0 ] == " Stop" ){
175
- Serial.println (" <" );
176
- Serial.print (" Arduino: " );
177
- Serial.println (" Moving Stopping!" );
178
- stopMotor (0 );
179
- }
180
- else
181
- {
182
- Serial.println (" <" );
183
- Serial.print (" Arduino: " );
184
- Serial.println (" Invalid Input!" );
165
+ delay (200 );
185
166
}
186
167
}
168
+
187
169
void showNewData () {
188
170
if (newData == true ) {
189
171
processData ();
@@ -194,7 +176,7 @@ void showNewData() {
194
176
}
195
177
}
196
178
197
- void readValues () {
179
+ void readValues (int motor_number ) {
198
180
sensor_value1[0 ] = sensor_value2[0 ];
199
181
sensor_value2[0 ] = analogRead (m1_sensor_pin);
200
182
}
0 commit comments