HM-10. BLE. Arduino UNO. Notify. Bluetooth. AT. iBeacon. Arrhythmia

15.- Pushbutton in Arduino sends (1) or (0) to App.

p110_UNO_boton_HM10.aia (184.2 KB)

  • When you press the Pushbutton7, (1) or (0) is sent to the app.
    As it receives (1) or (0) it will change the color of the btn_color to green or red.
    Notification (RegisterForString) is used.
// Juan A. Villalpando
// 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 BLE1(2, 3);

int valor = HIGH;
int valor_anterior = HIGH;

void setup(){
  Serial.begin(9600);
  BLE1.begin(9600);
  pinMode(7,INPUT);
}

void loop(){
  valor = digitalRead(7);
  if (valor == HIGH &&  valor_anterior != HIGH) { 
   Serial.println("Pulsado");
   valor_anterior = valor;
   BLE1.print("1");
   delay(10);
   } 
   if (valor == LOW && valor_anterior != LOW) { 
   Serial.println("NO");
   valor_anterior = valor;
   BLE1.print("0");
   delay(10);
   }   
}

1 Like