Skip to content

Incompatible with usb keyboard demo from esp library #196

@PeterHindes

Description

@PeterHindes

The following imports conflict with eachother. This is an issue as I would like to use usb and bluetooth keyboards in the same program.

// Bluetooth Libraries
#include <BleKeyboard.h>

// USB Libraries
#include "USB.h"
#include "USBHIDKeyboard.h"

The full program looks somewhat like this

// Bluetooth Libraries
#include <BleKeyboard.h>
BleKeyboard bleKeyboard;

// USB Libraries
#include "USB.h"
#include "USBHIDKeyboard.h"
USBHIDKeyboard Keyboard;

// Button On Board Feather
const int buttonPin = 0;
int buttonState = 0;  // variable for reading the pushbutton status

String msg = "Hello Gamer";

void setup() {
  Serial.begin(115200);
  delay(1000);
  
  Serial.println("Starting BLE work!");
  bleKeyboard.begin();
  
  Keyboard.begin();
  USB.begin();

  pinMode(buttonPin, INPUT_PULLUP);
}

void loop() {
  bleKeyboard.setBatteryLevel(98);
  buttonState = digitalRead(buttonPin);
  // Serial.println("checking button");
  // Serial.println(buttonState == LOW);
  if (buttonState == LOW){
    if(bleKeyboard.isConnected()) {
      Serial.println("Using Bluetooth");
      bleKeyboard.print(msg);
    } 
    else {
      Serial.println("Using USB");
      Keyboard.print(msg);
    }
    delay(500);
  }
  delay(10);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions