I have a problem.I want to creeate a a project with arduino,to be more specific i want to creeate a 2 wheels robot,and I want to control the robot from my android phone.I already made the app that i need in android studio. So i tested the app with arduino incorporated led 13. I tested first butons,and after the voice control with diferent sketch,all works fine.
#include <SoftwareSerial.h>
String voice;
#define bTx 11
#define bRx 10
#define led 13
SoftwareSerial bluetooth(bTx, bRx);
void setup() {
pinMode(led, OUTPUT);
bluetooth.begin(9600);
}
void loop() {
if (bluetooth.available()) {
char comand = (char)bluetooth.read();
switch (comanda) {
case 'W':
digitalWrite(led, HIGH);
break;
case 'S':
digitalWrite(led, LOW);
break;
}
}
}
This is the code for remote control with buttons.
#include <SoftwareSerial.h>
#define led 13
//TX, RX respetively
SoftwareSerial BT(11, 10);
String voice;
void setup() {
BT.begin(9600);
Serial.begin(9600);
pinMode(13, OUTPUT);
}
void loop() {
while (BT.available()){ //Check if there is an available byte to read
delay(10); //Delay added to make thing stable
char c = BT.read(); //Conduct a serial read
if (c == '#') {break;} //Exit the loop when the # is detected after the word
voice += c; //Shorthand for voice = voice + c
}
if (voice.length() > 0) {
Serial.println(voice);
if(voice == "go")
{
digitalWrite(13, HIGH);
}
else if(voice == "stop")
{
digitalWrite(13, LOW);
}
}
voice="";
}
And this is for voice remote control test.
How can i put all in one sketch? I tried diferent ways and i didn't figure it out. I mean i want to use just one sketch for both remote control(buttons and voice control).When i upload it in diferent sketch it work. I dont want to use two sketchs one for butons,and one for voice. My android app include buttons and voice control