Skip to content

Instantly share code, notes, and snippets.

@sweemeng
Last active Mar 12, 2021
Embed
What would you like to do?
Build using M5Atom with the following library. https://github.com/T-vK/ESP32-BLE-Keyboard
#include <M5Atom.h>
#include <BleKeyboard.h>
#include <FastLED.h>
#define NUM_LEDS 25
#define DATA_PIN 27
CRGB leds[NUM_LEDS];
BleKeyboard bleKeyboard("EscapeVIM");
int redButton[NUM_LEDS] = {
0,1,1,1,0,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
0,1,1,1,0,
};
void setPixels(int pixels[]){
for(int i=0;i<NUM_LEDS;i++){
if(pixels[i] == 1)
leds[i] = CRGB::Red;
if(pixels[i] == 0)
leds[i] = CRGB::Black;
}
FastLED.show();
}
void setup() {
M5.begin(true,false,true);
Serial.begin(115200);
Serial.println("Initializing");
bleKeyboard.begin();
FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(20);
}
void loop() {
setPixels(redButton);
M5.Btn.read();
if(bleKeyboard.isConnected()) {
if(M5.Btn.isPressed()){
Serial.println("Exiting vim");
bleKeyboard.write(KEY_ESC);
delay(1000);
bleKeyboard.print(":wq");
delay(1000);
bleKeyboard.write(KEY_RETURN);
delay(1000);
}
}
delay(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment