Created
January 10, 2021 16:16
-
-
Save yukilabo/c50b1d705deacbe7d0d1a9173176d8ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//This example code is in the Public Domain (or CC0 licensed, at your option.) | |
//By Evandro Copercini - 2018 | |
// | |
//This example creates a bridge between Serial and Classical Bluetooth (SPP) | |
//and also demonstrate that SerialBT have the same functionalities of a normal Serial | |
#include "BluetoothSerial.h" | |
#include <M5StickC.h> | |
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED) | |
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it | |
#endif | |
BluetoothSerial SerialBT; | |
void setup() { | |
M5.begin(); | |
Serial.begin(115200); | |
SerialBT.begin("ESP32test"); //Bluetooth device name | |
Serial.println("The device started, now you can pair it with bluetooth!"); | |
} | |
void loop() { | |
M5.update(); | |
if ( M5.BtnA.wasPressed() ) { | |
Serial.println("BtnA.wasPressed() == TRUE"); | |
M5.Lcd.fillScreen(WHITE); | |
SerialBT.write(0xFE); | |
SerialBT.write(0xFE); | |
SerialBT.write(0xA2); | |
SerialBT.write(0xE0); | |
SerialBT.write(0x1C); | |
SerialBT.write(0x00); | |
SerialBT.write(0x01); | |
SerialBT.write(0xFD); | |
} | |
if ( M5.BtnA.wasReleased() ) { | |
Serial.println("BtnA.wasReleased() == TRUE"); | |
M5.Lcd.fillScreen(BLACK); | |
SerialBT.write(0xFE); | |
SerialBT.write(0xFE); | |
SerialBT.write(0xA2); | |
SerialBT.write(0xE0); | |
SerialBT.write(0x1C); | |
SerialBT.write(0x00); | |
SerialBT.write(0x00); | |
SerialBT.write(0xFD); | |
} | |
// if (Serial.available()) { | |
// SerialBT.write(Serial.read()); | |
// } | |
// if (SerialBT.available()) { | |
// if (SerialBT.read() == 0xFE && | |
// SerialBT.read() == 0xFE && | |
// SerialBT.read() == 0xE0 && | |
// SerialBT.read() == 0xA2 && | |
// SerialBT.read() == 0x04) | |
// { | |
// Serial.println("Command Recv"); | |
// Serial.println("Mode = "); | |
// Serial.write(SerialBT.read() + 0x30); | |
// Serial.write(SerialBT.read() + 0x30); | |
// } | |
// | |
//// Serial.write(SerialBT.read()); | |
// } | |
delay(20); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment