Permalink
Browse files

Added SoftwareSerial example

  • Loading branch information...
1 parent fa3b65d commit cd7b68c66948143a3fc955527b65956089e86a96 @pictux pictux committed Oct 19, 2012
Showing with 34 additions and 0 deletions.
  1. +34 −0 examples/chatSoftwareSerial/chatSoftwareSerial.ino
@@ -0,0 +1,34 @@
+/*
+ Simple Arduino Chat
+ Set "Both NL & CR" as line ending
+*/
+
+#include <SoftwareSerial.h>
+
+SoftwareSerial mySerial(2, 3); // RX, TX
+String msg = "";
+char c;
+
+void setup()
+{
+ Serial.begin(9600);
+
+ Serial.println("Arduino Chat");
+ mySerial.begin(9600);
+}
+
+void loop() // run over and over
+{
+ if (mySerial.available()) {
+ c = mySerial.read();
+ if (c == '\n') {
+ Serial.println(msg);
+ msg = "";
+ } else {
+ msg += c;
+ }
+ }
+
+ if (Serial.available())
+ mySerial.write(Serial.read());
+}

0 comments on commit cd7b68c

Please sign in to comment.