Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Config begin
- */
- #define SerialSpeed 9600
- /*
- Config end
- */
- #define
- String inputString0 = "";
- boolean string0Complete = false;
- String inputString1 = "";
- boolean string1Complete = false;
- void setup() {
- Serial.begin(SerialSpeed);
- Serial1.begin(SerialSpeed);
- inputString0.reserve(200);
- inputString1.reserve(200);
- }
- void loop() {
- // print the string when a newline arrives:
- if (string0Complete) {
- Serial1.println(inputString0);
- // clear the string:
- inputString0 = "";
- string0Complete = false;
- }
- if (string1Complete) {
- Serial.println(inputString1);
- // clear the string:
- inputString1 = "";
- string1Complete = false;
- }
- }
- /*
- SerialEvent occurs whenever a new data comes in the
- hardware serial RX. This routine is run between each
- time loop() runs, so using delay inside loop can delay
- response. Multiple bytes of data may be available.
- */
- void serialEvent() {
- while (Serial.available()) {
- // get the new byte:
- char inChar = (char)Serial.read();
- // add it to the inputString:
- inputString0 += inChar;
- // if the incoming character is a newline, set a flag
- // so the main loop can do something about it:
- if (inChar == '\n') {
- string0Complete = true;
- }
- }
- }
- void serialEvent1() {
- while (Serial1.available()) {
- // get the new byte:
- char inChar = (char)Serial1.read();
- // add it to the inputString:
- inputString1 += inChar;
- // if the incoming character is a newline, set a flag
- // so the main loop can do something about it:
- if (inChar == '\n') {
- string1Complete = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment