RuiViana

If_Fora_Do LOOP.ino

Jan 16th, 2019
226
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SoftwareSerial.h>
  2. int RX_PIN = 2;
  3. int TX_PIN = 3;
  4. int BAUD_IDE = 9600;
  5. int BAUD_WEIGHT_SENSOR = 9600;
  6. String serialData = "";
  7. SoftwareSerial mySerial = SoftwareSerial(RX_PIN, TX_PIN);
  8.  
  9. void setup()
  10. {
  11.   mySerial.begin(BAUD_WEIGHT_SENSOR);
  12.   Serial.begin(BAUD_IDE);
  13. }
  14. void loop()
  15. {
  16.   while (mySerial.available())
  17.   {
  18.     int inChar = mySerial.read();
  19.     if (inChar != '\n')
  20.     {
  21.       serialData += (char)inChar;
  22.     }
  23.     else
  24.     {
  25.       int dataSize = serialData.length();
  26.       Serial.print(serialData); Serial.print(" length: ");
  27.       Serial.print(dataSize); Serial.print("\n");
  28.       delay(3000);
  29.       serialData = "";
  30.     }
  31.   } serialData = "";
  32. }
RAW Paste Data