-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmikeometer.ino
228 lines (202 loc) · 5.52 KB
/
mikeometer.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
// http://www.adafruit.com/products/420
#include <Adafruit_GFX.h> // Core graphics library
#include <RGBmatrixPanel.h> // Hardware-specific library
#define F2(progmem_ptr) (const __FlashStringHelper *)progmem_ptr
#include <EEPROM.h>
//#include <avr/wdt.h>
/*
#define CLK 8 // MUST be on PORTB! (Use pin 11 on Mega)
#define LAT 10
#define OE 9
#define A A0
#define B A1
#define C A2
#define resetpin 5
#define NEWLINE '\n'
*/
//Or, if you're using a Mega
#define CLK 11 // MUST be on PORTB! (Use pin 11 on Mega)
#define LAT A3
#define OE 9
#define A A0
#define B A1
#define C A2
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, true);
//There's no RAM left on an Uno.
//BITCH WE MEGA NOW
String str;
const char fuckyou1[] PROGMEM = "BLAME";
const char fuckyou2[] PROGMEM = "MIKE";
String strbuf = "";
int textX = matrix.width(),
textMin = sizeof(str) * -16, //a safe default
hue = 0,
hue2 = 128;
float millidays = 0;
bool iwasreset = true;
//String ohbill = "1234567890ABCDEF Dan Sucks Ordinary Normal Dongs"; //debug
String fuckyou;
int stringlength = 7;
//char serbuf[64];
typedef struct{
char currentChar;
char previousChar;
bool headerReceived;
bool tailerReceived = false;
String incommingString = "";
unsigned long headerTimestamp;
int headerTimeout = 500;
} parserstate_t;
parserstate_t parser;
boolean hasData(void){
return parser.tailerReceived;
}
void clearState(void){
parser.tailerReceived = false;
parser.headerReceived = false;
parser.currentChar = 0;
parser.previousChar = 0;
}
//Serial RX Buffer
void serialEvent(){
//Update state
parser.previousChar = parser.currentChar;
parser.currentChar = Serial.read();
//Serial.print(parser.currentChar);
//Serial.println(parser.previousChar);
//Header has been received
if(parser.currentChar == '@' && parser.previousChar == '@' && parser.headerReceived == false) {
//Serial.println("Header Received");
parser.headerTimestamp = millis();
parser.headerReceived = true;
parser.tailerReceived = false;
parser.currentChar = '\0';
parser.previousChar = '\0';
parser.incommingString = "";
}
//Tail has been received
else if(parser.headerReceived && !parser.tailerReceived){
parser.incommingString += parser.currentChar;
if(parser.currentChar == '@' && parser.previousChar == '@') {
//Serial.println("Tailer Received");
parser.tailerReceived = true;
parser.headerReceived = false;
parser.currentChar = '\0';
parser.previousChar = '\0';
}
}
//Garbage
else{
}
}
void EEPROMWriteString(String& str){
if(str.length() >= EEPROM.length() || str.length() > 255) {
Serial.println("EEROR: String longer than EEPROM");
return;
}
else{
const char* c_string;
char stringLength = str.length();
Serial.println(stringLength, DEC);
c_string = str.c_str();
EEPROM.write(0, stringLength);
for(int i = 0; i < stringLength; i++){
EEPROM.write(i+1, *(c_string + i));
}
}
}
String EEPROMReadString(void){
String stringBuffer;
char stringLength = EEPROM.read(0);
if(stringLength < 1) {
Serial.println("Error: No length String Found");
return stringBuffer;
}
else{
for(int i=0; i < stringLength; i++){
stringBuffer += (char)EEPROM.read(i+1);
}
return stringBuffer;
}
}
void setup() {
pinMode(7, OUTPUT); //no, i'm worse than that
digitalWrite(7, HIGH);
matrix.begin();
matrix.setTextWrap(false);
matrix.setTextSize(1);
Serial.begin(9600);
Serial.print("WHY ARE WE IN SETUP\n");
//EEPROM.put(0,ohbill);
delay(100);
fuckyou = EEPROMReadString();
delay(100);
//Serial.print(fuckyou);
textMin = sizeof(fuckyou) * -(fuckyou.length()); //i am a bad person
clearState();
}
void loop() {
byte i;
// Clear background
matrix.fillScreen(0);
matrix.setTextColor(matrix.ColorHSV(1023, 255, 255, true));
matrix.fillScreen(0);
//scroll
matrix.setTextColor(matrix.ColorHSV(hue, 255, 255, true)); //blue
matrix.setCursor(textX, 8);
matrix.print(fuckyou);
//counter
matrix.setTextColor(matrix.ColorHSV(hue2, 255, 255, true)); //red
matrix.setCursor(0, 0);
millidays = ((float)millis() / 1000 / 86400); //86.4 seconds
matrix.print(millidays, 3);
//Scrolls the text. Looks dirty because it is.
if ((--textX) < textMin) textX = matrix.width();
// Update display
matrix.swapBuffers(false);
hue += 14;
if (hue >= 1536) hue -= 1536;
hue2 += 30;
if (hue2 >= 1536) hue -= 1536;
delay(50); //slows down the scroll
// if (digitalRead(2) == HIGH)
//{
if (Serial.available() > 0) {
if (hasData()) {
if (parser.incommingString.substring(0, parser.incommingString.length() - 2) == "reset") {
clearState();
reset();
}
else if (parser.incommingString.substring(0, parser.incommingString.length() - 2) == "yo") {
clearState();
yo();
}
else{
clearState();
fuckyou = parser.incommingString.substring(0, parser.incommingString.length() - 2);
EEPROMWriteString("days since " + fuckyou);
reset();
}
}
}
//if (strbuf.equals("reset")){
// Serial.print("Reset found");
//reset();
//}
// }
}
void reset() {
asm volatile (" jmp 0");
}
//Yobiquiti framework compliance
void yo() {
matrix.fillScreen(0b1001100000011010); //branding compliance
matrix.setTextColor(matrix.ColorHSV(400, 512, 512, false));
matrix.setCursor(0, 0);
matrix.setTextSize(2);
matrix.print("Yo!");
matrix.swapBuffers(false);
matrix.setTextSize(1);
delay(2600);
}
//20151227_2145