-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathNotifyBoard.pde
More file actions
578 lines (506 loc) · 14.7 KB
/
NotifyBoard.pde
File metadata and controls
578 lines (506 loc) · 14.7 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
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
/*
Copyright 2010 Charles Yarnold charlesyarnold@gmail.com
NotifyBoard is free software: you can redistribute it and/or modify it under the terms of
the GNU General Public License as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later version.
NotifyBoard is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with NotifyBoard.
If not, see http://www.gnu.org/licenses/.
*/
/* Includes various minor modifications by London Hackspace */
/*
This sketch requires the arduino Library from:
http://github.com/solexious/MatrixDisplay
Version 0.4
*/
//#include <FatReader.h>
//#include <SdReader.h>
//#include <avr/pgmspace.h>
#include <TimedAction.h>
//#include "WaveUtil.h"
//#include "WaveHC.h"
/*SdReader card; // This object holds the information for the card
FatVolume vol; // This holds the information for the partition on the card
FatReader root; // This holds the information for the filesystem on the card
FatReader f; // This holds the information for the file we're play
WaveHC wave; // This is the only wave (audio) object, since we will only play one at a time*/
#include "MatrixDisplay.h"
#include "DisplayToolbox.h"
#include "font.h"
// Required when using Makefile - would be nice to get rid of this
void scroll();
void initText(void);
void drawString(int x, int y, char* c);
void drawStringW(int x, int y, char* c);
// Easy to use function
#define setMaster(dispNum, CSPin) initDisplay(dispNum,CSPin,true)
#define setSlave(dispNum, CSPin) initDisplay(dispNum,CSPin,false)
// 4 = Number of displays
// Data = 10
// WR == 11
// False - we dont need a shadow buffer for this example. saves 50% memory!
// Init Matrix
MatrixDisplay disp(4,15,14, false);
MatrixDisplay dispW(1,4,5, false);
// Pass a copy of the display into the toolbox
DisplayToolbox toolbox(&disp);
DisplayToolbox toolboxW(&dispW);
// Text settings
int x;
boolean scrolling;
int minLeft;
// Prepare boundaries
int X_MAX = 0;
int Y_MAX = 0;
int X_MAXW = 0;
int Y_MAXW = 0;
int jonty = 0;
int car = 0;
// Pins for car control
#define CAR_FWD 9
#define CAR_BACK 11
#define CAR_LEFT 8
#define CAR_RIGHT 10
#define FWD_TURN_TIME 600
#define BACK_TURN_TIME 600
#define DRIVE_TIME 250
//serial in stuff
#define INLENGTH 162
char inString[INLENGTH+1];
char inSerialString[INLENGTH+1];
int inCount;
TimedAction timedAction = TimedAction(35, scroll);
void setup() {
Serial.begin(9600);
timedAction.disable();
// Fetch bounds
X_MAX = disp.getDisplayCount() * disp.getDisplayWidth();
Y_MAX = disp.getDisplayHeight();
X_MAXW = dispW.getDisplayCount() * dispW.getDisplayWidth();
Y_MAXW = dispW.getDisplayHeight();
// Prepare displays
// The first number represents how the buffer/display is stored in memory. Could be useful for reorganising the displays or matching
// he physical layout
// The number is a array index and is sequential from 0. You can't use 4-8. You must use the numbers 0-4
disp.setMaster(0,16);
disp.setSlave(1,17);
disp.setSlave(2,18);
disp.setSlave(3,19);
dispW.setMaster(0,6);
//wave hc stuff
byte i;
//putstring("Free RAM: "); // This can help with debugging, running out of RAM is bad
//Serial.println(freeRam()); // if this is under 150 bytes it may spell trouble!
// Set the output pins for the DAC control. This pins are defined in the library
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
// pin13 LED
pinMode(6, OUTPUT);
/*
// if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you
if (!card.init()) { //play with 8 MHz spi (default faster!)
putstring_nl("Card init. failed!"); // Something went wrong, lets print out why
sdErrorCheck();
while(1); // then 'halt' - do nothing!
}
// enable optimize read - some cards may timeout. Disable if you're having problems
card.partialBlockRead(true);
// Now we will look for a FAT partition!
uint8_t part;
for (part = 0; part < 5; part++) { // we have up to 5 slots to look in
if (vol.init(card, part))
break; // we found one, lets bail
}
if (part == 5) { // if we ended up not finding one :(
putstring_nl("No valid FAT partition!");
sdErrorCheck(); // Something went wrong, lets print out why
while(1); // then 'halt' - do nothing!
}
// Lets tell the user about what we found
putstring("Using partition ");
Serial.print(part, DEC);
putstring(", type is FAT");
Serial.println(vol.fatType(),DEC); // FAT16 or FAT32?
// Try to open the root directory
if (!root.openRoot(vol)) {
putstring_nl("Can't open root dir!"); // Something went wrong,
while(1); // then 'halt' - do nothing!
}
// Whew! We got past the tough parts.
putstring_nl("Ready!");*/
// INITALISE
dispW.clear();
//drawStringW(1,0,"HELLO");
//toolboxW.setPixel(0,0, 1);
//drawCharW(0, 0, *"H");
dispW.syncDisplays();
//delay(5000);
initText();
}
//************************ START LOOP **********************
void loop()
{
if (Serial.available() > 0)
{
inCount = 0;
do {
inSerialString[inCount] = Serial.read(); // get it
if (inSerialString[inCount] == 10) break;
if (inCount > INLENGTH) break;
//Serial.println(inString[inCount]);
if (inSerialString[inCount] > 0 ) inCount++;
}
while (1==1);
inSerialString[inCount] = 0;
if(strstr(inSerialString,"$W$")){
// Send srting to mini board
char* miniString = inSerialString;
miniString +=3;
dispW.clear();
drawStringW(0,0,miniString);
dispW.syncDisplays();
}
else{
for(int a=0; a<162; a++){
inString[a] = inSerialString[a];
}
timedAction.disable();
if (strlen(inString) < 21)
{
x = floor ((128 - ((strlen(inString)*6) - 1)) / 2);
scrolling = false;
minLeft = 0;
}
else
{
x = X_MAX;
scrolling = true;
minLeft = 0 - (strlen(inString)*6);
}
if (strstr(inString,"jonty"))
digitalWrite(13, HIGH); // turn on pullup resistors
else
digitalWrite(13, LOW); // turn on pullup resistors
if (strstr(inString,"car")) {
if (strlen(inString) > 3) {
char car_cmd = inString[3];
switch (car_cmd){
case '1':
digitalWrite(CAR_LEFT, HIGH);
digitalWrite(CAR_FWD, HIGH);
delay(FWD_TURN_TIME);
digitalWrite(CAR_LEFT, LOW);
digitalWrite(CAR_FWD, LOW);
break;
case '2':
digitalWrite(CAR_RIGHT, HIGH);
digitalWrite(CAR_FWD, HIGH);
delay(FWD_TURN_TIME);
digitalWrite(CAR_RIGHT, LOW);
digitalWrite(CAR_FWD, LOW);
break;
case '3':
digitalWrite(CAR_LEFT, HIGH);
digitalWrite(CAR_BACK, HIGH);
delay(BACK_TURN_TIME);
digitalWrite(CAR_LEFT, LOW);
digitalWrite(CAR_BACK, LOW);
break;
case '4':
digitalWrite(CAR_RIGHT, HIGH);
digitalWrite(CAR_BACK, HIGH);
delay(BACK_TURN_TIME);
digitalWrite(CAR_RIGHT, LOW);
digitalWrite(CAR_BACK, LOW);
break;
case '5':
digitalWrite(CAR_FWD, HIGH);
delay(DRIVE_TIME);
digitalWrite(CAR_FWD, LOW);
break;
case '6':
digitalWrite(CAR_BACK, HIGH);
delay(DRIVE_TIME);
digitalWrite(CAR_BACK, LOW);
break;
case '7':
digitalWrite(CAR_LEFT, HIGH);
delay(DRIVE_TIME);
digitalWrite(CAR_LEFT, LOW);
break;
case '8':
digitalWrite(CAR_RIGHT, HIGH);
delay(DRIVE_TIME);
digitalWrite(CAR_RIGHT, LOW);
break;
}
}
}
disp.clear();
drawString(x,0,inString);
disp.syncDisplays();
//playfile("PING.WAV");
Serial.print("Displaying: ");
Serial.println(inString);
if (scrolling) timedAction.enable();
}
if (strstr(inString,"jonty"))
digitalWrite(13, HIGH); // turn on pullup resistors
else
digitalWrite(13, LOW); // turn on pullup resistors
if (strstr(inString,"car")) {
if (strlen(inString) > 3) {
char car_cmd = inString[3];
switch (car_cmd){
case '1':
digitalWrite(CAR_LEFT, HIGH);
digitalWrite(CAR_FWD, HIGH);
delay(FWD_TURN_TIME);
digitalWrite(CAR_LEFT, LOW);
digitalWrite(CAR_FWD, LOW);
break;
case '2':
digitalWrite(CAR_RIGHT, HIGH);
digitalWrite(CAR_FWD, HIGH);
delay(FWD_TURN_TIME);
digitalWrite(CAR_RIGHT, LOW);
digitalWrite(CAR_FWD, LOW);
break;
case '3':
digitalWrite(CAR_LEFT, HIGH);
digitalWrite(CAR_BACK, HIGH);
delay(BACK_TURN_TIME);
digitalWrite(CAR_LEFT, LOW);
digitalWrite(CAR_BACK, LOW);
break;
case '4':
digitalWrite(CAR_RIGHT, HIGH);
digitalWrite(CAR_BACK, HIGH);
delay(BACK_TURN_TIME);
digitalWrite(CAR_RIGHT, LOW);
digitalWrite(CAR_BACK, LOW);
break;
case '5':
digitalWrite(CAR_FWD, HIGH);
delay(DRIVE_TIME);
digitalWrite(CAR_FWD, LOW);
break;
case '6':
digitalWrite(CAR_BACK, HIGH);
delay(DRIVE_TIME);
digitalWrite(CAR_BACK, LOW);
break;
case '7':
digitalWrite(CAR_LEFT, HIGH);
delay(DRIVE_TIME);
digitalWrite(CAR_LEFT, LOW);
break;
case '8':
digitalWrite(CAR_RIGHT, HIGH);
delay(DRIVE_TIME);
digitalWrite(CAR_RIGHT, LOW);
break;
}
}
}
disp.clear();
drawString(x,0,inString);
disp.syncDisplays();
//playfile("PING.WAV");
Serial.print("Displaying: ");
Serial.println(inString);
if (scrolling) timedAction.enable();
}
timedAction.check();
}
// ******************************** END LOOP **********************************
//wave hc stuff
/*
// this handy function will return the number of bytes currently free in RAM, great for debugging!
int freeRam(void)
{
extern int __bss_end;
extern int *__brkval;
int free_memory;
if((int)__brkval == 0) {
free_memory = ((int)&free_memory) - ((int)&__bss_end);
}
else {
free_memory = ((int)&free_memory) - ((int)__brkval);
}
return free_memory;
}
void sdErrorCheck(void)
{
if (!card.errorCode()) return;
putstring("\n\rSD I/O error: ");
Serial.print(card.errorCode(), HEX);
putstring(", ");
Serial.println(card.errorData(), HEX);
while(1);
}
// Plays a full file from beginning to end with no pause.
void playcomplete(char *name) {
// call our helper to find and play this name
playfile(name);
while (wave.isplaying) {
// do nothing while its playing
}
// now its done playing
}
void playfile(char *name) {
// see if the wave object is currently doing something
if (wave.isplaying) {// already playing something, so stop it!
wave.stop(); // stop it
}
// look in the root directory and open the file
if (!f.open(root, name)) {
putstring("Couldn't open file ");
Serial.print(name);
return;
}
// OK read the file and turn it into a wave object
if (!wave.create(f)) {
putstring_nl("Not a valid WAV");
return;
}
// ok time to play! start playback
wave.play();
}*/
//sure display
void drawCharW(int x, int y, char c)
{
if(c==46){
toolboxW.setPixel(x, 0+y, 0);
toolboxW.setPixel(x, 1+y, 0);
toolboxW.setPixel(x, 2+y, 0);
toolboxW.setPixel(x, 3+y, 0);
toolboxW.setPixel(x, 4+y, 0);
toolboxW.setPixel(x, 5+y, 0);
toolboxW.setPixel(x, 6+y, 1);
}
else{
uint8_t dots;
for (char col=0; col< 5; col++) {
dots = pgm_read_byte_near(&myfont[c][col]);
for (char row=0; row < 8; row++) {
if (x+col<0)
{
}
else if (dots & (0x80>>row)) // only 7 rows.
toolboxW.setPixel(x+col, y+row, 1);
else
toolboxW.setPixel(x+col, y+row, 0);
}
}
}
}
void drawChar(int x, int y, char c)
{
uint8_t dots;
for (char col=0; col< 5; col++) {
dots = pgm_read_byte_near(&myfont[c][col]);
for (char row=0; row < 8; row++) {
if (x+col<0)
{
}
else if (dots & (0x80>>row)) // only 7 rows.
toolbox.setPixel(x+col, y+row, 1);
else
toolbox.setPixel(x+col, y+row, 0);
}
}
}
// Write out an entire string (Null terminated)
void drawString(int x, int y, char* c)
{
for(char i=0; i< strlen(c); i++)
{
if(x>-6)
{
if(x<X_MAX)
{
drawChar(x, y, c[i]);
}
}
x+=6; // Width of each glyph
}
}
void drawStringW(int x, int y, char* c)
{
for(char i=0; i< strlen(c); i++)
{
if(x>-6)
{
if(x<X_MAXW)
{
drawCharW(x, y, c[i]);
}
}
if(c[i]==46){
x+=2;
}
else{
x+=6; // Width of each glyph
}
}
}
void fadeIn(void)
{
for(int i=0; i<16; ++i) // The displays have 15 different brightness settings
{
// This will set the brightness for ALL displays
toolbox.setBrightness(i);
// Alternatively you could set them individually
// disp.setBrightness(displayNumber, i);
delay(200); // Let's wait a bit or you'll miss it!
}
}
void initText(void)
{
drawString(0,0,"London Hackspace");
disp.syncDisplays();
fadeIn();
disp.clear();
drawString(0,0,"NotificationBoard 0.4");
disp.syncDisplays();
fadeIn();
disp.clear();
delay(100);
drawString(0,0,"Loading, Please wait");
disp.syncDisplays();
delay(500);
disp.clear();
disp.syncDisplays();
delay(500);
drawString(0,0,"Loading, Please wait");
disp.syncDisplays();
delay(500);
disp.clear();
disp.syncDisplays();
delay(500);
drawString(0,0,"Loading, Please wait");
disp.syncDisplays();
delay(500);
disp.clear();
disp.syncDisplays();
delay(500);
disp.clear();
drawString(0,0,"Ready for input");
disp.syncDisplays();
fadeIn();
disp.clear();
disp.syncDisplays();
}
void scroll()
{
x--;
if (x<minLeft) x = X_MAX;
disp.clear();
drawString(x,0,inString);
disp.syncDisplays();
}