i am trying RH_ASK code mix with BLE-Keyboard(version 0.3.2).
it is my code-
#include <RH_ASK.h>
#ifdef RH_HAVE_HARDWARE_SPI
#include <SPI.h> // Not actually used but needed to compile
#include <BleKeyboard.h>
#endif
RH_ASK driver(2000, 4, 5, 0); // pin_4 is RX , pin_5 is TX
BleKeyboard bleKeyboard;
int LED = 27; //
int LED_1 = 14;
int LED_2 = 12;
int RF_SIGNAL = 13;
unsigned long old_milli = 0;
void setup()
{
pinMode(LED, OUTPUT);
pinMode(LED_1, OUTPUT);
pinMode(LED_2, OUTPUT);
pinMode(RF_SIGNAL, OUTPUT);
digitalWrite(LED_1, LOW);
digitalWrite(LED_2, LOW);
digitalWrite(RF_SIGNAL, HIGH);
digitalWrite(LED,HIGH);
Serial.begin(115200);
Serial.println("Starting BLE work!");
bleKeyboard.begin();
#ifdef RH_HAVE_SERIAL
#endif
if (!driver.init())
#ifdef RH_HAVE_SERIAL
Serial.println("init failed");
#else
;
#endif
delay(300); digitalWrite(RF_SIGNAL, LOW);
}
void loop()
{
uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
uint8_t buflen = sizeof(buf);
if (driver.recv(buf, &buflen)) // Non-blocking
{
int i;
if (buf[0] == 11) { Serial.println(" A "); VOL ();}
if (buf[0] == 21) { Serial.println(" B "); ESC (); }
if (buf[0] == 31) { Serial.println("C "); LEFT_LIGHT ();}
if (buf[0] == 32) { Serial.println("c "); OFF ();}
if (buf[0] == 41) { Serial.println(" D "); RIGHT_LIGHT (); }
if (buf[0] == 42) { Serial.println(" d "); OFF (); }
digitalWrite(RF_SIGNAL, HIGH); old_milli = millis();
}
if (millis() > (old_milli + 300)) { digitalWrite(RF_SIGNAL, LOW); }
} // -------------------------------------- END LOOP ------------------------------------
void LEFT_LIGHT () { digitalWrite(LED_1, HIGH); digitalWrite(LED_2, LOW); }
void RIGHT_LIGHT () { digitalWrite(LED_1, LOW); digitalWrite(LED_2, HIGH); }
void OFF () { digitalWrite(LED_1, LOW); digitalWrite(LED_2, LOW); }
void VOL () { if(bleKeyboard.isConnected()) { bleKeyboard.write(KEY_MEDIA_VOLUME_UP); } }
void ESC () { if(bleKeyboard.isConnected()) { bleKeyboard.write(KEY_ESC); } }
after uploading above code to esp32, Radio_head function are working good with
connected leds. my android bluetooth search "ESP32 Keyboard but not being connected. phone also state
but if remove RadioHead code all elements. it is connected and bluetooth keyboard functions working well.
please check my above mixed code . what is wrong in mixing. what code stop bluetooth connection. i want to use both of (RadioHead and Ble- keyboard functions ) here
.... thank you...