Hi, thanks for all help in the past.
I connected a HC-06 Bluetooth card to an Arduino Uno R3 (voltage divider for signal to HC-06). I want commands and program output via Bluetooth.
I now send individual characters as commands via the free app Bluetooth Graphics. If I send characters one by one from the phone the program acts as I expect, it repeats the character back to the phone. If I send more characters only the first comes out right.
I also added a case-statement to interpret the commands sent from the phone. If either of the allowed commands 'P' or 'p' is detected, a procedure will repeat "****" and the character 10 times. I did this to see better if execution speed goes up.
But after adding the case statement, if I enter an allowed command, the program just runs wild and repeats the printout of *****. I can stop this by letting the allowed command be followed by a random letter. 'P' will make the program run wild, "PX" will not and is interpreted as P.
How do I get some structure in this so that whatever characters I enter will be interpreted and not repeated?
#include <SoftwareSerial.h>
SoftwareSerial bluetoothSerial(9, 10);
void setup() {
bluetoothSerial.begin(9600); // Initialize software serial for Bluetooth module
pinMode(LED_BUILTIN, OUTPUT); // Initialize pin 13 as output
digitalWrite(LED_BUILTIN, LOW);
}
void print_repeat(char c) {
for (int itmp = 1; itmp <= 10; itmp++) {
bluetoothSerial.print("*************** >");
bluetoothSerial.print(c);
bluetoothSerial.println("<");
}
}
void loop() {
char data_b;
if (bluetoothSerial.available()) {
data_b = bluetoothSerial.read();
bluetoothSerial.write(data_b);
}
switch (data_b) {
case 'P':
digitalWrite(LED_BUILTIN, HIGH);
print_repeat('P');
break;
case 'p':
digitalWrite(LED_BUILTIN, LOW);
print_repeat('p');
break;
}
data_b = '-';
}
........

