@@ -31,7 +31,10 @@ SoftwareSerial BT(ARDU_RX, ARDU_TX);
31
31
#define LEFT 2
32
32
#define RIGHT 3
33
33
#define STOP 4
34
- #define START_CMD_CHAR ' *'
34
+ #define SPEED_CMD_CHAR ' s'
35
+ #define LEFT_CMD_CHAR ' l'
36
+ #define RIGHT_CMD_CHAR ' r'
37
+ #define FORWARD_CMD_CHAR ' f'
35
38
int wPos,fPos ,bPos,cycle,dir,rPos, superCycle,robotspeed;
36
39
boolean evitement;
37
40
String inText;
@@ -163,29 +166,29 @@ void loop()
163
166
164
167
// wait for incoming data
165
168
if (BT.available () > 0 ) {
166
-
167
- // parse incoming command start flag
168
169
get_char = BT.read ();
169
- if (get_char == START_CMD_CHAR) {
170
- BT.println (" commande recue " );
171
-
172
- // parse incoming command type
173
- ard_command = BT.parseInt (); // read the command
174
-
170
+ if (get_char == SPEED_CMD_CHAR) {
171
+ BT.println (" speed command " );
172
+ ard_command = BT.parseInt ();
173
+ if (ard_command != 0 )
174
+ {
175
+ robotspeed=(int )ard_command;
176
+ BT.println (" Speed set to : " );
177
+ BT.println (robotspeed);
178
+ }
179
+ } else if (get_char == LEFT_CMD_CHAR) {
180
+ BT.println (" left command" );
181
+ dir=LEFT;
182
+ } else if (get_char == RIGHT_CMD_CHAR) {
183
+ BT.println (" right command" );
184
+ dir=RIGHT;
185
+ } else if (get_char == FORWARD_CMD_CHAR) {
186
+ BT.println (" FORWARD command" );
187
+ dir=FORWARD;
175
188
}
176
189
}
177
190
178
191
179
- if (ard_command != 0 )
180
- {
181
- robotspeed=(int )ard_command;
182
- BT.println (" Speed set to : " );
183
- BT.println (robotspeed);
184
- }
185
-
186
-
187
-
188
-
189
192
if (cycle==5 ){
190
193
// No delay
191
194
} else {
@@ -226,6 +229,4 @@ void loop()
226
229
evitement = 1 ;
227
230
}
228
231
229
-
230
-
231
232
}
0 commit comments