arduino/testing/other/serial1.ino

57 lines
1.6 KiB
C++

/*-----( Import needed libraries )-----*/
#include <SoftwareSerial.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define SSerialRX 13 //Serial Receive pin
#define SSerialTX 12 //Serial Transmit pin
#define SSerialTxControl 4 //RS485 Direction control
#define RS485Transmit HIGH
#define RS485Receive LOW
#define Pin13LED 9
/*-----( Declare objects )-----*/
SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX
/*-----( Declare Variables )-----*/
int byteReceived;
int byteSend;
void setup() /****** SETUP: RUNS ONCE ******/
{
// Start the built-in serial port, probably to Serial Monitor
Serial.begin(9600);
Serial.println("Remote connector"); // Can be ignored
pinMode(Pin13LED, OUTPUT);
pinMode(SSerialTxControl, OUTPUT);
digitalWrite(SSerialTxControl, RS485Receive); // Init Transceiver
// Start the software serial port, to another device
RS485Serial.begin(9600); // set the data rate
}//--(end setup )---
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
//Copy input data to output
if (RS485Serial.available())
{
byteSend = RS485Serial.read(); // Read the byte
digitalWrite(Pin13LED, HIGH); // Show activity
delay(1);
digitalWrite(Pin13LED, LOW);
digitalWrite(SSerialTxControl, RS485Transmit); // Enable RS485 Transmit
RS485Serial.write(byteSend); // Send the byte back
//delay(10);
digitalWrite(SSerialTxControl, RS485Receive); // Disable RS485 Transmit
Serial.println("Bounce");
Serial.println(byteSend);
// delay(100);
}// End If RS485SerialAvailable
}//--(end main loop )---