re-implemented library. needs to be tested!

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2023-11-02 01:02:51 +01:00
parent 8a1b4685da
commit 78c1f77b87
3 changed files with 116 additions and 182 deletions

View File

@@ -1,45 +1,18 @@
/*
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!");
init485(2,3,4,5);
speed485(8000);
boolean sent = false;
while (!sent) {
sent = send485("This message is sent and received!");
}
}
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);
if (!send485(msg)){
Serial.print("Sending ");
Serial.print(msg);
Serial.println(" failed!");
}
void loop() {
// put your main code here, to run repeatedly:
if (available485()){
Serial.println("Received "+get485message());
}
}