// serialStr manages a serial port for you. When it recieves a
// complete string, it calls your choosen function to deal with it.
// And, it does all this, NON-BLOCKINGLY.
//
// Hide the mess of millis!
//
#include <serialStr.h> // You will need to install LC_baseTools to compile this.
serialStr serialManager;
void setup() {
Serial.begin(115200); // Fire up serial.
Serial.println("Type command and number."); // Tell user to type a word & number.
serialManager.setCallback(gotCom); // Tell serial manager it's callback function.
}
// This is the function that is called when the serial manager recieves complete string.
void gotCom(char* inStr) {
char instruction[20];
int magnitude;
sscanf(inStr, "%s %d", instruction, &magnitude); // Looking for text & int
Serial.print("Instruction: ");Serial.println(instruction); // Output the text portion we found.
Serial.print("Value: ");Serial.println(magnitude); // Output the int portion we found.
}
// In this case we only need to call idle();
void loop() {
idle(); // idle() runs stuff in the background. LC_baseTools has a lot of things that use this.
// If you need other loop() kinda' things, they can go here.
// Instead of delay(ms); You can now use sleep(ms); and loop will stop, idle() will still run.
}