diff options
author | Thibaut VIARD <thibaut.viard@atmel.com> | 2011-06-21 00:20:43 +0200 |
---|---|---|
committer | Thibaut VIARD <thibaut.viard@atmel.com> | 2011-06-21 00:20:43 +0200 |
commit | 0887b98f627500271b5ad8b3c4f6c7b90bc227ee (patch) | |
tree | ef8626954567ba22e392c68c8f3606416b07b5b5 /libraries/SoftwareSerial/examples | |
parent | 90c487402cefadb6a2aab907ab07075cbb759e34 (diff) |
Moving all AVR specific libraries to hardware/avr
Diffstat (limited to 'libraries/SoftwareSerial/examples')
-rw-r--r-- | libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino | 21 | ||||
-rwxr-xr-x | libraries/SoftwareSerial/examples/TwoPortRXExample/TwoPortRXExample.pde | 50 |
2 files changed, 71 insertions, 0 deletions
diff --git a/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino b/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino new file mode 100644 index 0000000..1f535bd --- /dev/null +++ b/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino @@ -0,0 +1,21 @@ +#include <SoftwareSerial.h> + +SoftwareSerial mySerial(2, 3); + +void setup() +{ + Serial.begin(57600); + Serial.println("Goodnight moon!"); + + // set the data rate for the SoftwareSerial port + mySerial.begin(4800); + mySerial.println("Hello, world?"); +} + +void loop() // run over and over +{ + if (mySerial.available()) + Serial.write(mySerial.read()); + if (Serial.available()) + mySerial.write(Serial.read()); +} diff --git a/libraries/SoftwareSerial/examples/TwoPortRXExample/TwoPortRXExample.pde b/libraries/SoftwareSerial/examples/TwoPortRXExample/TwoPortRXExample.pde new file mode 100755 index 0000000..1db4536 --- /dev/null +++ b/libraries/SoftwareSerial/examples/TwoPortRXExample/TwoPortRXExample.pde @@ -0,0 +1,50 @@ +#include <SoftwareSerial.h>
+
+SoftwareSerial ss(2, 3);
+SoftwareSerial ss2(4, 5);
+
+/* This sample shows how to correctly process received data
+ on two different "soft" serial ports. Here we listen on
+ the first port (ss) until we receive a '?' character. Then
+ we begin listening on the other soft port.
+*/
+
+void setup()
+{
+ // Start the HW serial port
+ Serial.begin(57600);
+
+ // Start each soft serial port
+ ss.begin(4800);
+ ss2.begin(4800);
+
+ // By default, the most recently "begun" port is listening.
+ // We want to listen on ss, so let's explicitly select it.
+ ss.listen();
+
+ // Simply wait for a ? character to come down the pipe
+ Serial.println("Data from the first port: ");
+ char c = 0;
+ do
+ if (ss.available())
+ {
+ c = (char)ss.read();
+ Serial.print(c);
+ }
+ while (c != '?');
+
+ // Now listen on the second port
+ ss2.listen();
+
+ Serial.println("Data from the second port: ");
+}
+
+void loop()
+{
+ if (ss2.available())
+ {
+ char c = (char)ss2.read();
+ Serial.print(c);
+ }
+}
+
|