Bluetooth question

I have a robot and have added a BT2S Slave to it, I would like to know if there is a way for it to know if it is paired with a bluetooth app or not so I can do a condition like: if(!paired){ roam(); } else{ //bluetooth code }

I tried using incomingByte but even if your paired it seems incomingByte = 0 if your inactive or between button pushes...

Any help would be appreciated.

I have that BT module and it has a pin called STATE, which is directly connected to the on-board led. That led blinks when it is NOT connected/paired, and is solid when it IS connected. The pulses happen every 400 - 500 milliseconds, so if you right a little piece of code that checks if the state is high for longer then that time frame, then you can assume it is connected. Or it could just be experiencing a glitch in which case you should see if it also transitions from high to low after it was declared connected.

Its not hard if you use the millis() function to keep track of the time passed. See the Blink Without Delay example sketch.

I should add, that the pulseIn() function doesn’t really work that great for this, so go with the Blink Without Delay example sketch.

Thanks, I'll look into that.

Any luck?

This sketch will not compile for you because you most likely don’t have the libraries, especially my TFT_Extension library, but it has the part your looking to do.

#include <ITDB02_Graph16.h>
#include <ITDB02_Touch.h>
#include <TFT_Extension_old.h>
// Declare which fonts we will be using
extern uint8_t SmallFont[];

//myGLCD(RS,WR,CS,RST,ALE,mode);
ITDB02 myGLCD(A1,A2,A0,A3,A5,ITDB32S);
//myTouch(TCLK,TCS,DIN,DOUT,IRQ);
ITDB02_Touch  myTouch(13,10,11,12,A4);
TFT_Extension_old myTFT(&myGLCD, &myTouch, LANDSCAPE);

int XC,YC;
boolean state;
long time = millis();
void setup()
{
  myGLCD.InitLCD(LANDSCAPE);
  myGLCD.clrScr();
  myGLCD.setFont(SmallFont);
  myTouch.InitTouch(LANDSCAPE);
  myTouch.setPrecision(PREC_EXTREME);
  myGLCD.fillScr(0,0,0);
  pinMode(37, INPUT);
}

void loop()
{  
  state = digitalRead(37);
  if(state)
  {
    long tmp = millis() - time ;
    myGLCD.printNumI(tmp,120,0);

    if(tmp > 1500) // 1500ms is more than enough time, but I was simulating the BT connection by hand.
      myGLCD.print("    connected", 0,0);
  }
  else 
  {
    time = millis();
    myGLCD.print("Not connected",0,0);
  }
}