-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLED_Display.pde
More file actions
104 lines (86 loc) · 2.19 KB
/
LED_Display.pde
File metadata and controls
104 lines (86 loc) · 2.19 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
import processing.serial.*;
int message_no = 0;
String message;
int state = 0;
boolean ready = true;
Serial display;
Twitter twitter;
int num_messages;
void setup() {
display = new Serial(this, Serial.list()[0]);
twitter = new Twitter("username", "password");
}
void draw() {
if (state == 0) {
try {
java.util.List statuses = twitter.getPublicTimeline();
Status status = (Status)statuses.get(message_no);
message = status.getText();
num_messages = statuses.size();
}
catch (TwitterException e) {
println(e.getStatusCode());
}
if (message.length() > 239) {
message_no++;
}
}
updateDisplay();
}
String outputMessage() {
String theseChars = "<BE>05<E><ID01><L1><PA><FE><MA><WC><FE>" + message + "<E><ID01><BF>06";
char check = 0;
for (int c = 0; c < theseChars.length(); c++) {
check = char(check ^ theseChars.charAt(c));
}
return "<ID01><L1><PA><FE><MA><WC><FE>" + message + hex(check, 2) + "<E>";
}
void updateDisplay() {
if (display.available() > 2) {
String serialData = display.readString();
if (serialData.equals("ACK")) {
state++;
ready = true;
}
else {
state = 0;
ready = true;
println(" I broke a bit, hold on a second...");
delay(1000);
}
println(" " + serialData);
}
if (ready) {
if (state == 0) {
display.write("<ID01><BE>05<E>");
ready = false;
}
else if (state == 1) {
display.write(outputMessage());
ready = false;
}
else if (state == 2) {
display.write("<ID01><BF>06<E>");
ready = false;
}
else if (state == 3) {
println(message_no + ": " + message + " - display updated!");
delay(1325 + (message.length() * 90));
message_no++;
state = 0;
ready = true;
if (message_no >= num_messages) {
try {
java.util.List statuses = twitter.getPublicTimeline();
message_no = 0;
Status status = (Status)statuses.get(message_no);
message = status.getText();
num_messages = statuses.size();
}
catch (TwitterException e) {
println(e.getStatusCode());
}
}
}
}
}