#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
String a;
int ledpin=13;
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() {
String b = "";
//while(Serial.available()) //seems not needed afterall, at least not yet
//{
b= mySerial.readString(); //data from bluetooth
Serial.println(b);
a += b;
if (b == "\r" ){
a.replace("\n", ""); // cut \n out of a
a.replace("\r", "");
if(a=="OK" || a=="ok")
{
digitalWrite(ledpin,HIGH);
delay(1000);
digitalWrite(ledpin,LOW);
}
else
{
blinkS(b);
}
a = "";
//}
}
}