I'm Using teensy 3 with teensyduino 1.14rc2 and Arduino 1.0.5 on Fedora 18
Couple of problems with the following code...
1. No output to Bluetooth serial console although bluetooth commands from my mobile are getting to the program. This works on Arduino with the same Bluetooth module.
2. I'm sending integers as one command but am getting the code executed in the next command.(maybe I'm missing something)
For example .. if I send 2, which should turn the led ON, nothing happens. The led does turn ON after the next command which can be anything valid/invalid 0,1,2,3,4,5, ...
I did a "cat /dev/ttyACM0 > text.log" but it also does not seem to have every thing that should have been printed. (a few lines are there though)
I have tried Serial2,3 with the same result.
Couple of problems with the following code...
1. No output to Bluetooth serial console although bluetooth commands from my mobile are getting to the program. This works on Arduino with the same Bluetooth module.
2. I'm sending integers as one command but am getting the code executed in the next command.(maybe I'm missing something)
For example .. if I send 2, which should turn the led ON, nothing happens. The led does turn ON after the next command which can be anything valid/invalid 0,1,2,3,4,5, ...
I did a "cat /dev/ttyACM0 > text.log" but it also does not seem to have every thing that should have been printed. (a few lines are there though)
I have tried Serial2,3 with the same result.
Code:
/**
* Bluetooth module
**/
HardwareSerial3 bt = HardwareSerial3();
int inByte = 0;
const int led1 = 23;
const int led2 = 12;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(19200);
bt.begin(9600);
bt.println();
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
}
void loop() {
if (bt.available() > 0) {
// get incoming byte:
digitalWrite(led1,LOW);
inByte = bt.parseInt();
bt.clear();
bt.print("I received: ");
bt.print(inByte,DEC);
Serial.print("I received: ");
Serial.println(inByte,DEC);
//Serial2.println("Command Recieved");
handleCommand(inByte);
delay(48);
digitalWrite(led1,HIGH);
}
}
void handleCommand(int command) {
switch(command){
case 0: //stop everything
digitalWrite(led2,LOW);
break;
case 1: //Motor1 Forward
digitalWrite(led2,LOW);
break;
case 2: //Motor1 Reverse
digitalWrite(led2,HIGH);
break;
case 3: //Motor2 Forward
digitalWrite(led2,HIGH);
break;
default:
bt.print("Unrecognized Command");
Serial.println("Unrecognized Command");
}
}