Trying to control LEDs via bluetooth with android phone

So far I'm putting together a robot that I can control with my android phone. Thus far I've been able to somehow manage to write a code and I can control the robot wirelessly.
I am coming to you all to work out some kinks in the programming to make the operation very fluid.
In the code below I am only controlling the arduino's ability to control 2 led's by either as numeric or alphabetic signal sent from my phone.

int val = 0;     // variable
#include <SoftwareSerial.h>
#define RxD 6
#define TxD 7
 
#define DEBUG_ENABLED  1
 
SoftwareSerial blueToothSerial(RxD,TxD);
 
void setup() 
{ 
  Serial.begin(9600);
  pinMode(RxD, INPUT);
  pinMode(TxD, OUTPUT);
  pinMode(13, OUTPUT);
  setupBlueToothConnection(); 
} 
 
void loop() 
{ 
  char recvChar;
  while(1){
    if(blueToothSerial.available() > 0){
      {int val = blueToothSerial.read(); }//check if there's any data sent from the remote bluetooth shield
      recvChar = blueToothSerial.read();
      Serial.print(recvChar);
      {recvChar = Serial.read();}
      {val = blueToothSerial.read();}
       // read value coming in from phone
       if(isDigit(val));{   // 
         digitalWrite(13, HIGH);
         delay(100);
         digitalWrite(13, LOW);}         
  }
}}
void setupBlueToothConnection()
{
  blueToothSerial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400
  blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
  blueToothSerial.print("\r\n+STNA=Bluebot\r\n"); //set the bluetooth name as "Bluebot"
  blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
  blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
  delay(2000); // This delay is required.
  blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable 
  Serial.println("Bluebot is ready for your command!");
  delay(2000); // This delay is required.
  blueToothSerial.flush();
}

Hardware

Arduino Duemilanove AtMega 328
Bluetooth shield from trossen robotics http://www.seeedstudio.com/wiki/index.php?title=Bluetooth_Shield
1 LEDs
Android Phone (T-mobile g2)
Application on phone: Bluetooth SPP <- Great app by the way!

Here is what I WANT it to do.

  • When LED command is received as a numeric digit...turn on LED attached to 13
  • Do not turn on upon receiving any kind of signal that is not numeric

Here is what it is doing right now

  • Turns LED on no matter what signal is sent from phone.

What was your question?

What is wrong with my code?

Can you or anyone assist in making corrections?

Marquezso:
What is wrong with my code?

I don't know. Explain what you think should happen and what is actually happening?

  while(1){
    if(blueToothSerial.available() > 0){
      {int val = blueToothSerial.read(); }//check if there's any data sent from the remote bluetooth shield
      recvChar = blueToothSerial.read();
      Serial.print(recvChar);
      {recvChar = Serial.read();}
      {val = blueToothSerial.read();}
       // read value coming in from phone
       if(isDigit(val));{   // 
         digitalWrite(13, HIGH);
         delay(100);
         digitalWrite(13, LOW);}         
  }

Ok. Let's work through your, somewhat pointless, infinite loop inside an already infinite loop() and see if I understand it.
If there is at least one character available from bluetooth, create a local variable val to read it, then discard it as val goes instantly out of scope.
Then read another one (whether available or not) into a local (to loop()) variable called recvChar and print it.
Then read one (whether available or not) from Serial into the local variable called recvChar.
Then read another one (whether available or not) into a global variable called val and test it, ignoring the result of the test, because of the semicolon at the end of the if statement.
Turn the light on, wait 100 milliseconds, then turn it off.
Then do it all again.

The light appears to stay on because that's what you tell it to do. There isn't enough time between turning it off, and turning it back on again unconditionally, for you to see it happening.