You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.5 KiB
63 lines
1.5 KiB
/* |
|
* Demonstrates how to use LCDisplay 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. |
|
*/ |
|
|
|
// include the library code: |
|
#include <LiquidCrystal.h> |
|
#include <SoftRS485.h> |
|
|
|
#define Max485_RO 2 // read-output of Max485 |
|
#define Max485_RE 8 // not-read-enable of Max485 |
|
#define Max485_DE 8 // data enable of Max485 |
|
#define Max485_DI 9 // data input of Max485 |
|
|
|
#define LCD_RS 10 |
|
#define LCD_EN 11 |
|
#define LCD_D4 4 |
|
#define LCD_D5 5 |
|
#define LCD_D6 6 |
|
#define LCD_D7 7 |
|
|
|
#define PROGRAM "RS485-Nano 2.2 / LCDReceive 1.2" |
|
|
|
// initialize the library by associating any needed LCD interface pin with the arduino pin number it is connected to |
|
LiquidCrystal lcd(LCD_RS, LCD_EN, LCD_D4, LCD_D5, LCD_D6, LCD_D7); |
|
|
|
void setup() { |
|
Serial.begin(115200); |
|
init485(Max485_RO,Max485_RE,Max485_DE,Max485_DI); // library initialization: |
|
|
|
// set up the LCD's number of columns and rows: |
|
lcd.begin(16, 4); |
|
// Print a message to the LCD. |
|
printMessage(PROGRAM); |
|
|
|
} |
|
|
|
void printMessage(String s){ |
|
Serial.println(s); |
|
lcd.clear(); |
|
int line = 0; |
|
int col = 0; |
|
auto cstr = s.c_str(); |
|
for (int i=0;i<s.length();i++){ |
|
if (col == 0 && cstr[i] == ' ') continue; |
|
if (cstr[i] == '{' || cstr[i] == '}') continue; |
|
lcd.print(cstr[i]); |
|
col++; |
|
if (cstr[i]==',' || col==16){ |
|
line++; |
|
col=0; |
|
lcd.setCursor(col, line); |
|
} |
|
} |
|
} |
|
|
|
void loop() { |
|
if (available485()) { |
|
printMessage(get485message()); |
|
} |
|
}
|
|
|