neu-implementierung. Funktioniert einigermaßen, interferiert aber mit anderen timer-basierten bibliotheken

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2023-10-31 21:21:57 +01:00
parent 900e4e436e
commit 8a1b4685da
5 changed files with 191 additions and 105 deletions

View File

@@ -0,0 +1,24 @@
/*
This sketch demonstrates, how to use the SoftRS485 library.
This library makes use of Arduinos timer 1
*/
#include <SoftRS485.h>
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
}
void loop(){
if (available485()){ // check if we have received anything
Serial.print("messageReceived: ");
Serial.println(get485Message()); // read the received message
}
}

View File

@@ -27,9 +27,6 @@ void setup() {
}
}
void messageReceived(String message){
}
void loop(){
if (available485()){ // check if we have received anything
Serial.print("messageReceived: ");
@@ -39,6 +36,10 @@ void loop(){
count++;
char msg[128];
(message+count).toCharArray(msg,128);
send485(msg);
if (!send485(msg)){
Serial.print("Sending ");
Serial.print(msg);
Serial.println(" failed!");
}
}
}

View File

@@ -0,0 +1,33 @@
/*
This sketch demonstrates, how to use the SoftRS485 library.
This library makes use of Arduinos timer 1
*/
#include <SoftRS485.h>
const int buttonPin = 10; // the number of the pushbutton pin
boolean button_state = true;
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
pinMode(buttonPin, INPUT_PULLUP);
}
void loop(){
boolean new_state = digitalRead(buttonPin);
if (new_state != button_state){
button_state = new_state;
if (new_state == LOW){
send485("Button pressed");
} else {
send485("Button released");
}
}
}