Advertisement
Guest User

SoftwareSerial

a guest
Mar 25th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.32 KB | None | 0 0
  1. #include <SoftwareSerial.h>
  2. #include <SPI.h>
  3.  
  4. #define PIN_BLUETOOTH_RX 17
  5. #define PIN_BLUETOOTH_TX 16
  6.  
  7. #define PIN_GSM_RX 19
  8. #define PIN_GSM_TX 18
  9.  
  10.  
  11. SoftwareSerial BluetoothSerial(PIN_BLUETOOTH_RX, PIN_BLUETOOTH_TX);
  12. SoftwareSerial Gsm(PIN_GSM_RX, PIN_GSM_TX);
  13. String m_strIncomeBluetooth, m_strSerialIncome, m_strGsmIncome;
  14.  
  15. void setup()
  16. {
  17.     Serial.begin(57600);
  18.     Gsm.begin(57600); //Sim800L Modul
  19.     BluetoothSerial.begin(57600); //HC06 Bluetooth Modul kann gelesen werden, da es zuletzt initialisiert wurde
  20. }
  21.  
  22. void loop()
  23. {
  24.     int c;
  25.     while ((c = Gsm.read()) != -1)m_strGsmIncome += (char)c; //Lese GSM Input und in einen String speichern
  26.     while ((c = BluetoothSerial.read()) != -1) m_strIncomeBluetooth += (char)c; //Lese Bluetooth Input und in einen String speichern
  27.  
  28.     while (Serial.available())
  29.     {
  30.         c = Serial.read();  m_strSerialIncome += (char)c; //Lese HW-Serial und in einen String speichern
  31.         Gsm.write(c);  //Übertrage Befehl an das GSM Modul
  32.     }
  33.  
  34.  
  35.  
  36.     if (m_strGsmIncome.length() > 0) { Serial.println("Gsm: " + m_strGsmIncome); m_strGsmIncome = ""; }
  37.     if (m_strIncomeBluetooth.length() > 0) { Serial.println("Bluetooth Data: " + m_strIncomeBluetooth); m_strIncomeBluetooth = ""; }
  38.  
  39.    
  40.  
  41.     if (m_strSerialIncome.length() > 0) {
  42.         Serial.println(m_strSerialIncome);
  43.         m_strSerialIncome = "";
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement