-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathi2c_20x4_v1.ino
More file actions
61 lines (56 loc) · 937 Bytes
/
Copy pathi2c_20x4_v1.ino
File metadata and controls
61 lines (56 loc) · 937 Bytes
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
#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h>
#define BUF_SIZ 20;
hd44780_I2Cexp lcd;
String s;
byte b[80];
int i;
int j;
byte v;
int ready;
void setup()
{
Serial.begin(9600);
lcd.begin(20,4);
lcd.print(".");
}
void loop()
{
// Serial has a buffer of 64 bytes, but our display
// uses 80. So the python code sends a 2 (STX)
// followed by the bytes to print on the LCD, and
// capped-off with a 3 (ETX) which is our cue to
// actually send the (complete) data to the LCD.
while (Serial.available())
{
v = Serial.read();
if(v == 2)
{
// Start of Text
i = 0;
}
else if(v == 3)
{
// end of Text
ready = 1;
}
else if(i < 80)
{
// body
b[i] = v;
i++;
}
}
if(ready == 1)
{
j = 0;
lcd.clear();
while(j < i)
{
lcd.write(b[j]);
j++;
}
ready = 0;
}
}