1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-05 16:24:12 +01:00
Arduino/build/shared/examples/04.Communication/MultiSerialMega/MultiSerialMega.ino

41 lines
815 B
Arduino
Raw Normal View History

2009-07-11 02:34:59 +02:00
/*
Mega multple serial test
Receives from the main serial port, sends to the others.
Receives from serial port 1, sends to the main serial (Serial 0).
This example works only on the Arduino Mega
The circuit:
* Any serial device attached to Serial port 1
* Serial monitor open on Serial port 0:
created 30 Dec. 2008
modified 20 May 2012
by Tom Igoe & Jed Roach
2009-07-11 02:34:59 +02:00
2010-02-23 23:31:12 +01:00
This example code is in the public domain.
2009-07-11 02:34:59 +02:00
*/
void setup() {
// initialize both serial ports:
Serial.begin(9600);
Serial1.begin(9600);
}
void loop() {
// read from port 1, send to port 0:
if (Serial1.available()) {
int inByte = Serial1.read();
Serial.write(inByte);
2009-07-11 02:34:59 +02:00
}
// read from port 0, send to port 1:
if (Serial.available()) {
int inByte = Serial.read();
Serial1.write(inByte);
}
2009-07-11 02:34:59 +02:00
}