Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. void getNumber(){
  2.   scratch = "";    // clear scratch for a new scan
  3.   /* Data takes form:
  4.    *
  5.    * +---------+----+----+----+----+----+----+----+----+----+-----+----+----+---------+---------+---------+
  6.    * | 2 (STX) | D1 | D2 | D3 | D4 | D5 | D6 | D7 | D8 | D9 | D10 | C1 | C2 | 13 (CR) | 10 (LF) | 3 (ETX) |
  7.    * +---------+----+----+----+----+----+----+----+----+----+-----+----+----+---------+---------+---------+
  8.    *
  9.   */
  10.  
  11.   char c = Serial.read();               // get the first character
  12.  
  13.   while (c != 2){c = Serial.read();}    // if its not STX, keep going till it is
  14.                                         // (though this is bad!)
  15.   if (c == 2){                          // now that we have STX
  16.     while ( c != 3 ){                   // loop through all new date till we get ETX
  17.       c = Serial.read();
  18.       scratch += c;                     // and append it to scratch
  19.     }
  20.   }
  21.  
  22.   scratch = scratch.replace(13, '\0');    // clean away
  23.   scratch = scratch.replace(10, '\0');
  24.   scratch = scratch.toLowerCase();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement