Created
February 18, 2022 11:47
-
-
Save nmwilk/24a1eedfd2adb25cc609764bd95ff7e4 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
#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