Guest User

ESP32 BLE Media Controller Code

a guest
Apr 11th, 2026
63
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.87 KB | None | 0 0
  1. #include <Wire.h>
  2. #include <Adafruit_GFX.h>
  3. #include <Adafruit_SSD1306.h>
  4. #include <BleKeyboard.h>
  5. #include <WiFi.h>
  6. #include <WebServer.h>
  7. #include <esp_bt.h>
  8.  
  9. // WIFI
  10. const char* ssid = "TD";
  11. const char* password = "boom boom";
  12.  
  13. WebServer server(80);
  14.  
  15. // PINS =
  16. #define CLK 18
  17. #define DT  19
  18. #define SW  23
  19.  
  20. // OLED
  21. #define SCREEN_WIDTH 128
  22. #define SCREEN_HEIGHT 64
  23. Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
  24.  
  25. // BLE
  26. BleKeyboard bleKeyboard("ESP32 Controller", "Tanay", 100);
  27.  
  28. // STATE
  29. int volume = 50;
  30. bool isPlaying = false;
  31.  
  32. String track  = "No Track";
  33. String artist = "No Artist";
  34.  
  35. // ENCODER
  36. int lastCLK;
  37. unsigned long lastConnectedTime = 0;
  38.  
  39. //  SETUP
  40. void setup() {
  41.   Serial.begin(115200);
  42.  
  43.   pinMode(CLK, INPUT_PULLUP);
  44.   pinMode(DT, INPUT_PULLUP);
  45.   pinMode(SW, INPUT_PULLUP);
  46.  
  47.   lastCLK = digitalRead(CLK);
  48.  
  49.   Wire.begin(21, 22);
  50.  
  51.   if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
  52.     Serial.println("OLED FAIL");
  53.     while (1);
  54.   }
  55.  
  56.   display.clearDisplay();
  57.   display.setTextColor(WHITE);
  58.  
  59.   bleKeyboard.begin();
  60.   bleKeyboard.setDelay(0);
  61.  
  62.   // WIFI CONNECT
  63.   WiFi.begin(ssid, password);
  64.   Serial.print("Connecting to WiFi");
  65.  
  66.   while (WiFi.status() != WL_CONNECTED) {
  67.     delay(500);
  68.     Serial.print(".");
  69.   }
  70.  
  71.   Serial.println("\nConnected!");
  72.   Serial.println(WiFi.localIP());
  73.  
  74.   // HTTP ENDPOINT
  75.   server.on("/update", []() {
  76.     if (server.hasArg("track")) track = server.arg("track");
  77.     if (server.hasArg("artist")) artist = server.arg("artist");
  78.  
  79.     Serial.println("Track: " + track);
  80.     Serial.println("Artist: " + artist);
  81.  
  82.     server.send(200, "text/plain", "OK");
  83.   });
  84.  
  85.   server.begin();
  86. }
  87.  
  88. // LOOP
  89. void loop() {
  90.  
  91.   server.handleClient();
  92.  
  93.   // BLE CONNECTION HANDLING
  94.   static bool wasConnected = false;
  95.  
  96.   if (bleKeyboard.isConnected()) {
  97.     if (!wasConnected) {
  98.       Serial.println("BLE Connected");
  99.       wasConnected = true;
  100.     }
  101.     lastConnectedTime = millis();
  102.  
  103.   } else {
  104.     if (wasConnected) {
  105.       Serial.println("BLE Disconnected → restarting BLE");
  106.       wasConnected = false;
  107.  
  108.       delay(500);
  109.       Serial.println("Resetting BLE stack...");
  110.  
  111.       // turn off bluetooth completely
  112.       esp_bluedroid_disable();
  113.       esp_bluedroid_deinit();
  114.       esp_bt_controller_disable();
  115.  
  116.       // small delay
  117.       delay(500);
  118.  
  119.       // restart clean
  120.       ESP.restart();
  121.     }
  122.  
  123.     delay(500);
  124.     return;
  125.   }
  126.  
  127.   handleEncoder();
  128.   handleButton();
  129.   drawUI();
  130. }
  131.  
  132. // ENCODER
  133. void handleEncoder() {
  134.   static int lastStateCLK = HIGH;
  135.   int currentStateCLK = digitalRead(CLK);
  136.  
  137.   if (currentStateCLK != lastStateCLK) {
  138.  
  139.     if (digitalRead(DT) != currentStateCLK) {
  140.       volume = min(100, volume + 2);
  141.       bleKeyboard.write(KEY_MEDIA_VOLUME_UP);
  142.       Serial.println("VOL UP");
  143.     } else {
  144.       volume = max(0, volume - 2);
  145.       bleKeyboard.write(KEY_MEDIA_VOLUME_DOWN);
  146.       Serial.println("VOL DOWN");
  147.     }
  148.  
  149.     delay(3); // debounce
  150.   }
  151.  
  152.   lastStateCLK = currentStateCLK;
  153. }
  154.  
  155. // BUTTON
  156. void handleButton() {
  157.   static unsigned long lastPress = 0;
  158.  
  159.   if (digitalRead(SW) == LOW && millis() - lastPress > 300) {
  160.     lastPress = millis();
  161.  
  162.     isPlaying = !isPlaying;
  163.     bleKeyboard.write(KEY_MEDIA_PLAY_PAUSE);
  164.  
  165.     Serial.println("PLAY/PAUSE");
  166.   }
  167. }
  168.  
  169. // UI
  170. void drawUI() {
  171.   display.clearDisplay();
  172.  
  173.   display.setTextSize(1);
  174.  
  175.   // HEADER
  176.   display.setCursor(20, 0);
  177.   display.print("Now Playing");
  178.  
  179.   // TRACK
  180.   display.setCursor(0, 15);
  181.   display.print(track);
  182.  
  183.   // ARTIST
  184.   display.setCursor(0, 25);
  185.   display.print(artist);
  186.  
  187.   // STATE
  188.   display.setCursor(0, 35);
  189.   display.print(isPlaying ? "Playing" : "Paused");
  190.  
  191.   // VOLUME BAR
  192.   display.drawRect(0, 48, 128, 10, WHITE);
  193.   int fill = map(volume, 0, 100, 0, 126);
  194.   display.fillRect(1, 49, fill, 8, WHITE);
  195.  
  196.   display.display();
  197. }
Advertisement
Comments
  • Ulrloxel
    17 hours
    # CSS 0.83 KB | 0 0
    1. ✅ Leaked Exploit Documentation:
    2.  
    3. https://docs.google.com/document/d/1S1iTruSLkgEPO8QtTuo2twS4f2FoJ3_l0-p4GKqeAUY/edit?usp=sharing
    4.  
    5. This made me $13,000 in 2 days.
    6.  
    7. Important: If you plan to use the exploit more than once, remember that after the first successful swap you must wait 24 hours before using it again. Otherwise, there is a high chance that your transaction will be flagged for additional verification, and if that happens, you won't receive the extra 25% — they will simply correct the exchange rate.
    8.  
    9. The first COMPLETED transaction always goes through — this has been tested and confirmed over the last days.
    10.  
    11. Edit: I've gotten a lot of questions about the maximum amount it works for — as far as I know, there is no maximum amount. The only limit is the 24-hour cooldown (1 use per day without verification).
Add Comment
Please, Sign In to add comment