Merge branch 'nano-revision-2.0'

This commit is contained in:
2023-12-16 13:53:58 +01:00
3 changed files with 153 additions and 28 deletions
+18 -12
View File
@@ -1,22 +1,23 @@
/*
* Demonstrates how to use LCDisplay in conjunction with SoftRS485:
* Demonstrates how to use Read Buttons in conjunction with SoftRS485:
*
* The main _loop_ of this program listens on the RS485 bus.
* Whenever a message is received from the bus, it is displayed on the LCD.
* If a button is pressed, a corresponding flag is set.
* The main loop checks for the state of those flags and
* sends a message on the RS485 bus whenever a flag is set.
*/
// include the library code:
#include <SoftRS485.h>
#define PROGRAM "RS485-Nano 2.0.1"
#define PROGRAM "RS485-Nano 2.1 / Sender 1.1"
#define BTN_INT 2 // button interrupt pin
#define Max485_RO 3 // read-output of Max485
#define Max485_RE 5 // not-read-enable of Max485
#define Max485_DE 9 // data enable of Max485
#define Max485_DI 8 // data input of Max485
#define BTN_INT 3 // button interrupt pin
#define Max485_RO 2 // read-output of Max485
#define Max485_RE 3 // not-read-enable of Max485
#define Max485_DE 8 // data enable of Max485
#define Max485_DI 9 // data input of Max485
#define TRESHOLD 100000 // 100ms
#define TRESHOLD 200000 // 200ms
#define ID 0
// 0=Test
// 1=Arbeitszimmer
@@ -31,7 +32,7 @@ unsigned long times[8];
void setup() {
void setup(){
Serial.begin(115200);
init485(Max485_RO,Max485_RE,Max485_DE,Max485_DI); // library initialization:
pinMode(BTN_INT,INPUT_PULLUP);
@@ -73,7 +74,7 @@ void isr(){
#ifdef SEND_485
void send(int btn){
String s = "{nano:"+String(ID)+",btn:"+String(btn)+"}";
for (int i = 0; i<10; i++){
for (int i = 0; i<10; i++){
if (send485(s.c_str())) break;
Serial.println("collision detected, trying again:");
}
@@ -82,8 +83,13 @@ void send(int btn){
void loop(){
unsigned long now = micros();
boolean pause = true;
for (int i=0;i<8;i++){
if (states[i]){
if (pause){
delay(5);
pause=false;
}
if (now - times[i] > TRESHOLD){
#ifdef SEND_485
send(i+1);