Skip to content

Instantly share code, notes, and snippets.

@juanalonso
Created February 23, 2022 09:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanalonso/a397704accf0ff42decc32d503220519 to your computer and use it in GitHub Desktop.
Save juanalonso/a397704accf0ff42decc32d503220519 to your computer and use it in GitHub Desktop.
/*
* Mando pasadiapositivas (siguiente y anterior) por
* bluetooth, usando dos botones del Lolin32 (ESP32)
*/
#include <Bounce2.h>
#include <BleKeyboard.h>
#define PREV_GPIO 4
#define NEXT_GPIO 23
BleKeyboard bleKeyboard("KokuGorro", "Kokuma", 80);
bool estadoBoton = HIGH;
Bounce2::Button butPREV = Bounce2::Button();
Bounce2::Button butNEXT = Bounce2::Button();
int counter = 0;
void setup() {
bleKeyboard.begin();
butPREV.attach(PREV_GPIO, INPUT_PULLUP);
butPREV.interval(5);
butPREV.setPressedState(LOW);
butNEXT.attach(NEXT_GPIO, INPUT_PULLUP);
butNEXT.interval(5);
butNEXT.setPressedState(LOW);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
}
void loop() {
butPREV.update();
butNEXT.update();
if (bleKeyboard.isConnected()) {
if (butPREV.pressed()) {
bleKeyboard.write(KEY_LEFT_ARROW);
}
if (butNEXT.pressed()) {
bleKeyboard.write(KEY_RIGHT_ARROW);
}
digitalWrite(LED_BUILTIN, counter > 0);
counter = ++counter % 30;
}
delay(50);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment