Robot runs when it shouldn't - is there a passive BT signal?


#1

I have written code to make the Starter Robot controllable via Bluetooth through 2 apps. One is from Google Play (Bluetooth RC Control), the other is from Amazon (RC Bluetooth Control), because my kids have Kindle Fire tablets.

Here is the basic start (not including definitions) to the code:

void setup() { //Runs once at startup
bluetooth.begin(115200);
}

void loop() { //Runs until power-off

if (bluetooth.available()){
char cmd = readBT();
switch(cmd){
case ‘U’:
forward();
break;
case ‘D’:
backward();
break;
case ‘E’:
(etc)

When I turn the robot on it spins (for the Play app) or runs backwards (for the Amazon app) until BT is connected to the app and a command is given. I tried running the following function to clear the buffer in setup, but it didn’t help:

void serialFlush(){
while(bluetooth.available()>0){
char t = bluetooth.read();
}
}

Is there an initial or passive BT signal that the program is reading before the connection is established?


#2