Skip to content

Instantly share code, notes, and snippets.

@nmwilk
Created February 18, 2022 11:47
Show Gist options
  • Save nmwilk/24a1eedfd2adb25cc609764bd95ff7e4 to your computer and use it in GitHub Desktop.
Save nmwilk/24a1eedfd2adb25cc609764bd95ff7e4 to your computer and use it in GitHub Desktop.
#define BUF_SIZE 64
char simHubMessageBuf[BUF_SIZE];
RGBDigit rgbDigit(1, <your-pin-here>);
char gear = '-';
void setup() {
Serial.begin(115200);
memset(simHubMessageBuf, 0x0, BUF_SIZE);
// set up rgbdigit
rgbDigit.begin();
rgbDigit.clearAll();
}
void loop() {
if (Serial.available() > 0) {
Serial.readBytesUntil('{', simHubMessageBuf, BUF_SIZE);
int readCount = Serial.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