a scope could help , this code will also let us use led for debugging, it will flash 5xwhen booting up
if a=ok it will do a 1 second flash
if a<>ok then it will dump the variable a to the led, so the led will flash x amount of times(x number of flashes will be the ascii value of first char) then 1second delay then x number of flashes for second char.... till the variable is empty so,
(a=="OK\r\n") // 79flashes, 1sec pause, 75 flashes, 1 sec pause, 13 flashes, 1sec pause, 10 flashes
(a=="OK") // 79flashes, 1sec pause, 75 flashes,
(a=="ok") // 111flashes, 1sec pause, 107 flashes,
dont worry so much about getting flash count , but how many groups of flashes to tell us how long the string is, (according to the micro controller)
Code:
void blinkC(unsigned char b){
while (b>0){
digitalWrite(ledpin,HIGH);
delay(200);
digitalWrite(ledpin,LOW);
delay(200);
b--;
}
)
void blinkS(const char* ch){
while (*ch )
{
blinkC(*ch++);
delay(1000);
}
}
void setup()
{
pinMode(ledpin,OUTPUT);
Serial.begin(9600); //harware serial
mySerial.begin(9600); //bluetooth module, for sending AT-commands
blinkC(5);
delay(1000);
}
void loop() {
//while(Serial.available()) //seems not needed afterall, at least not yet
//{
a = "";
a= mySerial.readString(); //data from bluetooth
Serial.println(a);
if(a=="OK" || a=="ok")
{
digitalWrite(ledpin,HIGH);
delay(1000);
digitalWrite(ledpin,LOW);
}
else
{
blinkS(a);
}
//}
}