... | @@ -94,10 +94,16 @@ void loop() { |
... | @@ -94,10 +94,16 @@ void loop() { |
|
c[0] = (char) SerialBT.read();
|
|
c[0] = (char) SerialBT.read();
|
|
c[1] = '\0';
|
|
c[1] = '\0';
|
|
|
|
|
|
if(c[0] == '\r' || c[0] == '\n'){ // detect crlf (\r \n)
|
|
|
|
|
|
|
|
// check if the buffer is empty
|
|
if(// detect crlf (\r \n)
|
|
if(buffer[0] == '\0') return;
|
|
(
|
|
|
|
c[0] == '\r'
|
|
|
|
|| // OR
|
|
|
|
c[0] == '\n'
|
|
|
|
)
|
|
|
|
&& // AND
|
|
|
|
buffer[0] != '\0' // check if buffer is not empty
|
|
|
|
){
|
|
|
|
|
|
Serial.println(buffer);
|
|
Serial.println(buffer);
|
|
exeCommande();
|
|
exeCommande();
|
... | @@ -110,19 +116,16 @@ void loop() { |
... | @@ -110,19 +116,16 @@ void loop() { |
|
|
|
|
|
void exeCommande()
|
|
void exeCommande()
|
|
{
|
|
{
|
|
// led on
|
|
|
|
if(strcmp(buffer,"led on") == 0){
|
|
if(strcmp(buffer,"led on") == 0){
|
|
digitalWrite(LED, HIGH);
|
|
digitalWrite(LED, HIGH);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
// led off
|
|
|
|
if(strcmp(buffer,"led off") == 0){
|
|
if(strcmp(buffer,"led off") == 0){
|
|
digitalWrite(LED, LOW);
|
|
digitalWrite(LED, LOW);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
//default
|
|
|
|
SerialBT.println("Unknow command");
|
|
SerialBT.println("Unknow command");
|
|
}
|
|
}
|
|
``` |
|
``` |