-
Notifications
You must be signed in to change notification settings - Fork 1
/
LCD_Display_WiFi.ino
91 lines (75 loc) · 1.8 KB
/
LCD_Display_WiFi.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <LiquidCrystal.h>
#include <SPI.h>
#include <WiFiNINA.h>
#include <vrpc.h>
const char ssid[] = "<WLAN-SSID>";
const char pass[] = "<WLAN-PASSWORD>";
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
WiFiClient wifi;
VrpcAgent agent;
// last-values-cached
String lvc_text[2];
float lvc_number[2];
void setText(String text, int row = 0) {
clearRow(row);
lcd.print(text);
lvc_text[row > 0 ? 1 : 0] = text;
}
String getText(int row = 0) {
return lvc_text[row > 0 ? 1 : 0];
}
void setNumber(float number, int row = 0) {
clearRow(row);
lcd.print(String(number, 2));
lvc_number[row > 0 ? 1 : 0] = number;
}
float getNumber(int row = 0) {
return lvc_number[row > 0 ? 1 : 0];
}
void clearRow(int row) {
if (row == 0) {
lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(0, 0);
} else {
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setCursor(0, 1);
}
}
void connect() {
while (WiFi.status() != WL_CONNECTED) {
lcd.setCursor(0, 1);
lcd.print("Connect WiFi... ");
WiFi.begin(ssid, pass);
delay(1000);
}
lcd.print("OK");
delay(1000);
lcd.setCursor(0, 1);
lcd.print("Connect VRPC... ");
agent.connect();
}
void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
lcd.begin(16, 2);
lcd.print("Heisenware GmbH");
WiFi.begin(ssid, pass);
agent.begin(wifi);
connect();
}
void loop() {
agent.loop();
if (!agent.connected()) {
connect();
// restore text of second row
setText(lvc_text[1], 1);
}
}
VRPC_GLOBAL_FUNCTION(void, setText, String, int);
VRPC_GLOBAL_FUNCTION(void, setNumber, float, int);
VRPC_GLOBAL_FUNCTION(String, getText, int);
VRPC_GLOBAL_FUNCTION(float, getNumber, int);