@@ -12,9 +12,22 @@ char receivedChars[numChars];
12
12
13
13
boolean newData = false ;
14
14
15
+ String recievedString = " " ;
16
+
17
+
15
18
int m1_sensor_pin = A0;
16
19
int m1_sensor_value1 = 0 ;
17
20
int m1_sensor_value2 = 0 ;
21
+ int m1_rotation_int = 0 ;
22
+ String m1_rotation_direction = " " ;
23
+ String m1_rotation = " " ;
24
+
25
+ int m2_sensor_pin = A0;
26
+ int m2_sensor_value1 = 0 ;
27
+ int m2_sensor_value2 = 0 ;
28
+ int m2_rotation_int = 0 ;
29
+ String m2_rotation_direction = " " ;
30
+ String m2_rotation = " " ;
18
31
19
32
void setup () {
20
33
Serial.begin (9600 );
@@ -31,6 +44,10 @@ void loop() {
31
44
showNewData ();
32
45
}
33
46
47
+ // ////////////////////////////////////
48
+ // ////////////////////////////////////
49
+ // ////////////////////////////////////
50
+
34
51
void recvWithStartEndMarkers () {
35
52
static boolean recvInProgress = false ;
36
53
static byte ndx = 0 ;
@@ -64,21 +81,26 @@ void recvWithStartEndMarkers() {
64
81
}
65
82
66
83
void processData () {
67
- String recievedString = receivedChars;
84
+
85
+
86
+ recievedString = receivedChars;
87
+
88
+ m1_rotation_direction = getValue (recievedString, ' ,' , 0 );
89
+ m1_rotation = getValue (recievedString, ' ,' , 1 );
90
+ m1_rotation_int = m1_rotation.toInt ();
91
+
92
+ // comments
68
93
Serial.println (" <" );
69
94
Serial.print (" RevievedString: " );
70
95
Serial.println (recievedString);
71
- String m1_rotation_direction = getValue (recievedString, ' ,' , 0 );
72
- String m1_rotation = getValue (recievedString, ' ,' , 1 );
73
- int m1_rotation_int = m1_rotation.toInt ();
74
96
Serial.print (" Number of Rotations: " );
75
97
Serial.println (m1_rotation);
76
98
77
99
if (m1_rotation_direction == " Up" ) {
78
100
Serial.println (" <" );
79
101
Serial.print (" Arduino: " );
80
102
Serial.println (" Moving Up!" );
81
- pwm. setPWM ( 3 , 0 , 295 );
103
+ upMotor ( 3 );
82
104
while (1 ) {
83
105
readValues ();
84
106
Serial.println (m1_sensor_value2);
@@ -91,14 +113,13 @@ void processData() {
91
113
}
92
114
delay (500 );
93
115
}
94
- pwm.setPWM (3 , 0 , 0 );
95
-
116
+ stopMotor (3 );
96
117
}
97
118
else if (m1_rotation_direction == " Down" ) {
98
119
Serial.println (" <" );
99
120
Serial.print (" Arduino: " );
100
121
Serial.println (" Moving Down!" );
101
- pwm. setPWM ( 3 , 0 , 270 );
122
+ downMotor ( 3 );
102
123
while (1 ) {
103
124
readValues ();
104
125
Serial.println (m1_sensor_value2);
@@ -111,14 +132,14 @@ void processData() {
111
132
}
112
133
delay (500 );
113
134
}
114
- pwm. setPWM ( 3 , 0 , 0 );
135
+ stopMotor ( 3 );
115
136
}
116
137
117
- else if (strcmp (receivedChars, " Stop" )== 0 ){
138
+ else if (m1_rotation_direction == " Stop" ){
118
139
Serial.println (" <" );
119
140
Serial.print (" Arduino: " );
120
141
Serial.println (" Moving Stopping!" );
121
- pwm. setPWM ( 3 , 0 , 0 );
142
+ stopMotor ( 3 );
122
143
}
123
144
else
124
145
{
0 commit comments