Hi Everyone,
I'm trying to get my Arduino BT (OSEPP Bluetooth) to receive a number from my phone then play a tone. Eventually each number will have a unique tone (replicating DTMF tones). The problem I am having is that when I read the character (eg '1'), it doesn't store that character, instead it seems like its storing part of a header file but I'm not sure.
#include <SoftwareSerial.h> //Software Serial Port
#define RxD 0 // Arduino Tx and Rx pins as labeled on board
#define TxD 1
#define SOP '<'
#define EOP '>'
int led =13;
int toner = 11;
bool started = false;
bool ended = false;
SoftwareSerial blueToothSerial = SoftwareSerial(RxD,TxD);
void setup() { // runs every time the Arduino is plugged in to power
Serial.begin(9600); // set baud rate
pinMode(RxD, INPUT); // set Receive pin to input
pinMode(TxD, OUTPUT); // set Transmit pin to output
setupBlueToothConnection(); // initialize Bluetooth connection
pinMode(led, OUTPUT);
}
void loop() { // runs continuously after startup
char recvChar; // temp variable to buffer a received character
while(blueToothSerial.available() >0){ //Runs when data is incoming
ledBlink(500); //displays that there is data available
recvChar = blueToothSerial.read(); // if so, buffer the character
blueToothSerial.write(recvChar); // Send char to BT connection ...not working...
if(recvChar == SOP){
started = true;
ledBlink(2000);
}
else if(recvChar == EOP){
ended = true;
ledBlink(1000);
}
else {
if(recvChar == '1'){
playTone();
}
}
if (started == true && ended == true){
digitalWrite(led, HIGH);
delay(5000);
digitalWrite(led,LOW);
}
}
}
void setupBlueToothConnection() {
blueToothSerial.begin(9600); //Set Bluetooth BaudRate to default (38400)
blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the Bluetooth to slave mode
delay(2000); // This delay is required.
blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave Bluetooth inquirable
Serial.println("The slave Bluetooth is inquirable!");
delay(2000); // This delay is required.
blueToothSerial.flush();
}
void playTone(){
tone(toner, 4800, 500);
delay(1000);
}
void ledBlink(int length){ //lights the led for length
digitalWrite(led, HIGH);
delay(length);
digitalWrite(led,LOW);
}
Does anyone have any clues as to why it would not be storing a '1' in recvChar?