Skip to content

Instantly share code, notes, and snippets.

@nmwilk
Last active February 18, 2022 11:45
Show Gist options
  • Save nmwilk/2b98a7de7226933e1e86d6db0e0f6458 to your computer and use it in GitHub Desktop.
Save nmwilk/2b98a7de7226933e1e86d6db0e0f6458 to your computer and use it in GitHub Desktop.
#include "BluetoothSerial.h"
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
#define BUF_SIZE 64
char simHubMessageBuf[BUF_SIZE];
BluetoothSerial btSerial;
RGBDigit rgbDigit(1, <your-pin-here>);
char gear = '-';
void setup() {
Serial.begin(115200);
Serial.println("setup");
memset(simHubMessageBuf, 0x0, BUF_SIZE);
btSerial.begin("BT-DASH");
// set up rgbdigit
rgbDigit.begin();
rgbDigit.clearAll();
}
void loop() {
if (btSerial.available() > 0) {
btSerial.readBytesUntil('{', simHubMessageBuf, BUF_SIZE);
int readCount = btSerial.readBytesUntil('}', simHubMessageBuf, BUF_SIZE);
simHubMessageBuf[min(readCount, BUF_SIZE - 1)] = 0x0;
processMessage();
memset(simHubMessageBuf, 0x0, BUF_SIZE);
}
rgbDigit.setDigit(gear, 0, 255, 255, 255);
}
void processMessage() {
char msgType = simHubMessageBuf[0];
switch (msgType) {
case 'G':
gear = simHubMessageBuf[1];
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment