3.- Turn on-off 3 LEDs. Check LEDs Status.
p110i_UNO_HM10_3LED.aia (186.6 KB)
// http://kio4.com/arduino/161_HM10_BLE.htm
#include <SoftwareSerial.h>
// El TXD del m贸dulo al pin 2 (RX) del Arduino.
// El RXD del m贸dulo al pin 3 (TX) del Arduino.
SoftwareSerial HM10(2, 3);
#define LED11  11
#define LED12  12
#define LED13  13
char caracter = "";  
String mensaje = "";
String estado = "";
void setup() {
  Serial.begin(9600);
  HM10.begin(9600);
  pinMode(LED11, OUTPUT);
  pinMode(LED12, OUTPUT);
  pinMode(LED13, OUTPUT);
}
void loop(){
  if(HM10.available()) { 
  caracter = HM10.read();
  // Serial.println(caracter);
  mensaje = mensaje + caracter;
  if(caracter == NULL ) { 
     Serial.println(mensaje); 
     if (mensaje == "on11") {digitalWrite(LED11,HIGH); estado = "LED11 ON";}
     if (mensaje == "off11"){digitalWrite(LED11,LOW); estado = "LED11 OFF";}
     if (mensaje == "on12") {digitalWrite(LED12,HIGH); estado = "LED12 ON";}
     if (mensaje == "off12"){digitalWrite(LED12,LOW); estado = "LED12 OFF";} 
     if (mensaje.indexOf("on13") >= 0){digitalWrite(LED13, HIGH); estado = "LED13 ON";}
     if (mensaje.indexOf("off13") >= 0){digitalWrite(LED13, LOW); estado = "LED13 OFF";}
     if (mensaje == "check"){
     estado ="";
     if (digitalRead(LED11) == HIGH) {estado = "on11,";} else {estado = "off11,";}
     if (digitalRead(LED12) == HIGH) {estado = estado + "on12,";} else {estado = estado + "off12,";}
     if (digitalRead(LED13) == HIGH) {estado = estado + "on13";} else {estado = estado + "off13";}
    }
     HM10.print(estado.c_str()); 
     mensaje = "";
     delay(100);
     }
  } 
}
- Two ways:
 
if (mensaje == "on11") this means if message is equal to "on11"
if (mensaje.indexOf("on13") >= 0) this means if message contains "on13"
- RegisterForString (Notifiy), when the HM10.print...
 
HM10.print(estado.c_str()); 
... variable "estado" is automatically sent to the app, note that Clock is not required.
- Be careful, the MTU of the HM-10 is 20 bytes (package), the messages must be less than 19 bytes + NULL
 

























 