Advertisement
gm310509

Simple serial device test program

May 1st, 2024 (edited)
567
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | Source Code | 0 0
  1. #include <SoftwareSerial.h>
  2.  
  3. #define RX 2
  4. #define TX 3
  5. #define BAUD 9600
  6.  
  7. boolean echoOn = true;
  8.  
  9. SoftwareSerial ss (RX, TX);
  10.  
  11. void setup() {
  12.   Serial.begin(BAUD);
  13.   ss.begin(BAUD);
  14.   Serial.print("Simple serial device tester.");
  15. }
  16.  
  17. void loop() {
  18.   if (Serial.available()) {
  19.     char ch = Serial.read();
  20.     if (echoOn) {
  21.       Serial.println(ch);
  22.     }
  23.     ss.print(ch);
  24.   }
  25.  
  26.   if (ss.available()) {
  27.     char ch = ss.read();
  28.     Serial.print(ch);
  29.   }
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement