@@ -15,19 +15,19 @@ void ProcessData()
15
15
// initialize all motors and get them moving
16
16
for (int i = 0 ; i < NUMBER_MOTORS; i++)
17
17
{
18
- if (motor_commands[i][1 ] == 0 )
18
+ if (motor_commands[i][0 ] == 0 )
19
19
{
20
20
my_servo[i].write (100 );
21
21
}
22
- else if (motor_commands[i][1 ] == 1 )
22
+ else if (motor_commands[i][0 ] == 1 )
23
23
{
24
24
my_servo[i].write (80 );
25
25
}
26
- else if (motor_commands[i][1 ] == 2 )
26
+ else if (motor_commands[i][0 ] == 2 )
27
27
{
28
28
my_servo[i].write (90 );
29
29
}
30
- else if (motor_commands[i][1 ] == 3 )
30
+ else if (motor_commands[i][0 ] == 3 )
31
31
{
32
32
// call reset function (still needs to be written)
33
33
}
@@ -37,42 +37,41 @@ void ProcessData()
37
37
Invalid ();
38
38
}
39
39
}
40
+
41
+ bool go = true ;
42
+ int total_turns = 0 ;
40
43
44
+ while (go == true )
45
+ {
41
46
47
+ for (int i = 0 ; i < NUMBER_MOTORS; i++)
48
+ {
49
+ motor_sensor_counter2[i] = motor_sensor_counter1[i];
50
+ motor_sensor_counter1 = CheckSwitch (i,ports[i][0 ]);
42
51
43
- //
44
- /*
45
- // Print First Number
46
- Serial.println("---------");
47
- Serial.print("Motor 1: ");
48
- Serial.println(motor_rotation_number);
49
-
50
- while (true) {
51
-
52
- motor_sensor_counter2 = motor_sensor_counter1;
53
- checkswitch(motor_counter_port);
54
- motor_sensor_counter1 = output;
55
- delay(10);
52
+ if (motor_sensor_counter1 == 1 && motor_sensor_counter2 == 0 ) {
53
+ motor_commands[i][1 ] = motor_commands[i][1 ] - 1 ;
54
+ }
55
+ }
56
56
57
- if (motor_rotation_number == 0) {
58
- myservo1.write(90);
59
- break;
57
+ // stop motors that have reached 0
58
+ for (int i = 0 ; i < NUMBER_MOTORS; i++)
59
+ {
60
+ if (motor_commands[i][1 ] <= 0 ) {
61
+ my_servo[i].write (90 );
62
+ }
60
63
}
61
-
62
- if (digitalRead(motor_reset_port) == 0) {
63
- myservo1.write(90);
64
- break ;
64
+ // see how many turns are left in the array
65
+ for ( int i = 0 ; i < NUMBER_MOTORS; i++)
66
+ {
67
+ total_turns += motor_commands[i][ 1 ] ;
65
68
}
66
-
67
- if (motor_sensor_counter1 == 1 && motor_sensor_counter2 == 0) {
68
- motor_rotation_number--;
69
-
70
- // Print Number Every Time It Changes
71
- Serial.print("Motor 1: ");
72
- Serial.println(motor_rotation_number);
69
+ // exit loop if there are no more motor rotations remaining
70
+ if (total_turns <= 0 ) {
71
+ go = false ;
73
72
}
74
- } */
75
-
73
+ total_turns = 0 ;
74
+ }
76
75
// Send Finished Signal
77
76
Finished ();
78
77
}
@@ -139,42 +138,30 @@ void PopulateArray()
139
138
// ////////////////////////////////////////////////////////////////////////////
140
139
// ////////////////////////////////////////////////////////////////////////////
141
140
142
- void CheckSwitch (int switchPort)
141
+ void CheckSwitch (int motor_number, int switchPort)
143
142
{
144
- // /* Step 1: Update the integrator based on the input signal. Note that the
145
- // integrator follows the input, decreasing or increasing towards the limits
146
- // as determined by the input state (0 or 1). */
147
- // input = digitalRead(switchPort);
148
-
149
- // if (input == 0)
150
- // {
151
- // if (integrator > 0)
152
- // integrator--;
153
- // }
154
- // else if (integrator < MAXIMUM)
155
- // integrator++;
156
-
157
- // /* Step 2: Update the output state based on the integrator. Note that the
158
- // output will only change states if the integrator has reached a limit,
159
- // either 0 or MAXIMUM. */
160
-
161
- // if (integrator == 0)
162
- // output = 0;
163
- // else if (integrator >= MAXIMUM)
164
- // {
165
- // output = 1;
166
- // integrator = MAXIMUM; /* defensive code if integrator got corrupted */
167
- // }
168
-
169
- // /********************************************************* End of
170
- // debounce.c */
171
- }
143
+ /* Step 1: Update the integrator based on the input signal. Note that the
144
+ integrator follows the input, decreasing or increasing towards the limits
145
+ as determined by the input state (0 or 1). */
146
+ input[motor_number] = digitalRead (switchPort);
172
147
173
- /* void Reset1() {
174
- myservo1.write(100);
175
- while(true) {
176
- if(digitalRead(motor_reset_port) == 0){
177
- break;
178
- }
148
+ if (input[motor_number] == 0 )
149
+ {
150
+ if (integrator[motor_number] > 0 )
151
+ integrator[motor_number]--;
152
+ }
153
+ else if (integrator[motor_number] < MAXIMUM)
154
+ integrator[motor_number]++;
155
+
156
+ /* Step 2: Update the output state based on the integrator. Note that the
157
+ output will only change states if the integrator has reached a limit,
158
+ either 0 or MAXIMUM. */
159
+
160
+ if (integrator[motor_number] == 0 )
161
+ reuturn (0 )
162
+ else if (integrator[motor_number] >= MAXIMUM)
163
+ {
164
+ return (1 );
165
+ integrator[motor_number] = MAXIMUM; /* defensive code if integrator got corrupted */
179
166
}
180
- } */
167
+ }
0 commit comments