Skip to content

Instantly share code, notes, and snippets.

@lf-
Created March 13, 2017 05:22
Show Gist options
  • Save lf-/75965accd377fee4831e09329bad4bba to your computer and use it in GitHub Desktop.
Save lf-/75965accd377fee4831e09329bad4bba to your computer and use it in GitHub Desktop.
#include <SoftwareSerial.h>
const int MD49_RX = 8;
const int MD49_TX = 9;
const int SABER_TX = 10;
const int SABER_UNUSED = 11;
const int CMD_MD49 = 0x01;
const int CMD_SABER = 0x02;
SoftwareSerial md49(MD49_RX, MD49_TX);
SoftwareSerial sabertooth(SABER_UNUSED, SABER_TX);
int mode = 0;
void setup() {
Serial.begin(9600);
md49.begin(9600);
sabertooth.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
while (!Serial);
}
void loop() {
if (md49.available() > 0) {
digitalWrite(LED_BUILTIN, 1);
Serial.write(md49.read());
}
if (Serial.available() > 0) {
if (mode == 0) {
mode = Serial.read();
}
if (mode == CMD_MD49) {
byte received = Serial.read();
md49.write(received);
mode = 0;
} else if (mode == CMD_SABER) {
byte received = Serial.read();
sabertooth.write(received);
mode = 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment