first working implementation of timer-based RS485

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2023-10-31 17:17:40 +01:00
parent 10b96424cd
commit 900e4e436e
3 changed files with 220 additions and 30 deletions

View File

@@ -0,0 +1,44 @@
/*
This sketch demonstrates, how to use the SoftRS485 library.
This library makes use of Arduinos timer 1
*/
#include <SoftRS485.h>
int count = 0;
String message = "Message ";
void setup() {
Serial.begin(115200);
init485(2,3,4,5); // library initialization:
// connect pin 2 to RO of Max485
// connect pin 3 to ^RE of Max485
// connect pin 4 to DE of Max485
// connect pin 5 to DI of Max485
if (send485("Test")) {
// This should send "Test" if the line is free.
Serial.println("Test sent!");
}
if (!send485("Test2")) {
// This shoult fail, as transmission of "Test" should still be on the way
Serial.println("Test2 failed!");
}
}
void messageReceived(String message){
}
void loop(){
if (available485()){ // check if we have received anything
Serial.print("messageReceived: ");
Serial.println(get485Message()); // read the received message
// send another message everytime we have received one
count++;
char msg[128];
(message+count).toCharArray(msg,128);
send485(msg);
}
}