Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
237 lines (216 sloc) 6.78 KB
/* vim: set ft=c : */
/**
* Author: Leo Vidarte <http://nerdlabs.com.ar>
*
* This is free software:
* you can redistribute it and/or modify it
* under the terms of the GPL version 3
* as published by the Free Software Foundation.
*/
const int cols[5] = {9, 10, 11, 12, 13};
const int rows[7] = {2, 3, 4, 5, 6, 7, 8};
#define MSG_LEN 513
#define CHARSET_LEN 95
const char charset [CHARSET_LEN][5] = {
{0x00, 0x00, 0x00, 0x00, 0x00},
{0x21, 0x08, 0x42, 0x00, 0x80},
{0x52, 0x80, 0x00, 0x00, 0x00},
{0x02, 0xbe, 0xaf, 0xa8, 0x00},
{0x23, 0xe8, 0xe2, 0xf8, 0x80},
{0xce, 0x44, 0x44, 0x4e, 0x60},
{0x32, 0x10, 0xd9, 0x49, 0xa0},
{0x21, 0x00, 0x00, 0x00, 0x00},
{0x11, 0x08, 0x42, 0x10, 0x40},
{0x41, 0x08, 0x42, 0x11, 0x00},
{0x05, 0x5d, 0xf7, 0x54, 0x00},
{0x01, 0x09, 0xf2, 0x10, 0x00},
{0x00, 0x00, 0x06, 0x32, 0x00},
{0x00, 0x00, 0xe0, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x31, 0x80},
{0x08, 0x44, 0x44, 0x42, 0x00},
{0x74, 0x67, 0x5c, 0xc5, 0xc0},
{0x23, 0x28, 0x42, 0x13, 0xe0},
{0x74, 0x42, 0xe8, 0x43, 0xe0},
{0x74, 0x42, 0xe0, 0xc5, 0xc0},
{0x11, 0x95, 0x2f, 0x88, 0x40},
{0xfc, 0x3c, 0x10, 0xc5, 0xc0},
{0x32, 0x21, 0xe8, 0xc5, 0xc0},
{0xf8, 0x44, 0x22, 0x11, 0x00},
{0x74, 0x62, 0xe8, 0xc5, 0xc0},
{0x74, 0x62, 0xf0, 0x89, 0x80},
{0x03, 0x18, 0x06, 0x30, 0x00},
{0x03, 0x18, 0x06, 0x32, 0x00},
{0x00, 0x88, 0x82, 0x08, 0x00},
{0x00, 0x1c, 0x07, 0x00, 0x00},
{0x02, 0x08, 0x22, 0x20, 0x00},
{0x74, 0x62, 0x22, 0x00, 0x80},
{0x74, 0x6f, 0x5b, 0xc1, 0x80},
{0x74, 0x63, 0x1f, 0xc6, 0x20},
{0xf4, 0x63, 0xe8, 0xc7, 0xc0},
{0x74, 0x61, 0x08, 0x45, 0xc0},
{0xf4, 0x63, 0x18, 0xc7, 0xc0},
{0xfc, 0x21, 0xe8, 0x43, 0xe0},
{0xfc, 0x21, 0xe8, 0x42, 0x00},
{0x74, 0x61, 0x78, 0xc5, 0xe0},
{0x8c, 0x63, 0xf8, 0xc6, 0x20},
{0xf9, 0x08, 0x42, 0x13, 0xe0},
{0x38, 0x84, 0x21, 0x49, 0x80},
{0x8c, 0xa9, 0x8a, 0x4a, 0x20},
{0x84, 0x21, 0x08, 0x43, 0xe0},
{0x8e, 0xeb, 0x58, 0xc6, 0x20},
{0x8c, 0x73, 0x59, 0xc6, 0x20},
{0x74, 0x63, 0x18, 0xc5, 0xc0},
{0xf4, 0x63, 0xe8, 0x42, 0x00},
{0x74, 0x63, 0x1a, 0xc9, 0xa0},
{0xf4, 0x63, 0xea, 0x4a, 0x20},
{0x74, 0x60, 0xe0, 0xc5, 0xc0},
{0xf9, 0x08, 0x42, 0x10, 0x80},
{0x8c, 0x63, 0x18, 0xc5, 0xc0},
{0x8c, 0x62, 0xa5, 0x10, 0x80},
{0x8c, 0x63, 0x5a, 0xee, 0x20},
{0x8c, 0x54, 0x45, 0x46, 0x20},
{0x8c, 0x54, 0x42, 0x10, 0x80},
{0xf8, 0x44, 0x44, 0x43, 0xe0},
{0x31, 0x08, 0x42, 0x10, 0xc0},
{0x84, 0x10, 0x41, 0x04, 0x20},
{0x61, 0x08, 0x42, 0x11, 0x80},
{0x22, 0xa2, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x03, 0xe0},
{0x41, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x1c, 0x17, 0xc5, 0xe0},
{0x84, 0x3d, 0x18, 0xc7, 0xc0},
{0x00, 0x1d, 0x18, 0x41, 0xe0},
{0x08, 0x5f, 0x18, 0xc5, 0xe0},
{0x00, 0x1d, 0x1f, 0xc1, 0xe0},
{0x74, 0x61, 0xc8, 0x42, 0x00},
{0x00, 0x1f, 0x17, 0x85, 0xc0},
{0x84, 0x3d, 0x18, 0xc6, 0x20},
{0x20, 0x38, 0x42, 0x10, 0x60},
{0x20, 0x0e, 0x42, 0x13, 0x00},
{0x84, 0x25, 0x4c, 0x52, 0x40},
{0xe1, 0x08, 0x42, 0x10, 0x60},
{0x00, 0x35, 0x5a, 0xd6, 0xa0},
{0x00, 0x3d, 0x18, 0xc6, 0x20},
{0x00, 0x1d, 0x18, 0xc5, 0xc0},
{0x00, 0x3d, 0x1f, 0x42, 0x00},
{0x00, 0x1f, 0x17, 0x84, 0x20},
{0x00, 0x2d, 0x98, 0x42, 0x00},
{0x00, 0x1f, 0x07, 0x07, 0xc0},
{0x42, 0x3c, 0x84, 0x24, 0xc0},
{0x00, 0x23, 0x18, 0xc5, 0xe0},
{0x00, 0x23, 0x15, 0x28, 0x80},
{0x00, 0x2b, 0x5a, 0xd5, 0x40},
{0x00, 0x22, 0xa2, 0x2a, 0x20},
{0x00, 0x23, 0x17, 0x87, 0xc0},
{0x00, 0x3e, 0x17, 0x43, 0xe0},
{0x31, 0x08, 0x82, 0x10, 0xc0},
{0x21, 0x08, 0x47, 0x10, 0x80},
{0x61, 0x08, 0x22, 0x11, 0x80},
{0x00, 0x31, 0x51, 0x80, 0x00},
};
void setup() {
for (int i = 2; i <= 13; i++) {
pinMode(i, OUTPUT);
}
Serial.begin(9600);
}
void draw_char(char *c) {
int pos = 0;
for (int row = 0; row < 7; row++) {
for (int col = 0; col < 5; col++) {
digitalWrite(cols[col], (c[pos++] == '1' ? LOW: HIGH));
}
digitalWrite(rows[row], HIGH);
delayMicroseconds(500);
digitalWrite(rows[row], LOW);
}
}
void fixed_char(const char *c, int times) {
char buffer[40];
int pos = 0;
for (int j = 0; j < 5; j++) {
for (int i = 0; i < 8; i++) {
buffer[pos++] = ((c[j] << i) & 0x80 ? '1' : '0');
}
}
for (int i = 0; i < times; i++) {
draw_char(buffer);
}
}
void marquee_chars(const char *c1, const char *c2, int times) {
char buffer[35];
int pos_0 = 5;
int offset1 = 0;
int cpos;
int cindex;
int shift;
char value;
for (int frame = 0; frame < 6; frame++) {
int pos = 0;
for (int i = 0; i < 7; i++) {
for (int j = 0; j < 5; j++) {
if (j < pos_0) {
cpos = pos + offset1;
cindex = cpos / 8;
shift = cpos % 8;
value = ((c1[cindex] << shift) & 0x80 ? '1' : '0');
}
if (j == pos_0) {
value = '0';
}
if (j > pos_0) {
cpos = pos - pos_0 - 1;
cindex = cpos / 8;
shift = cpos % 8;
value = ((c2[cindex] << shift) & 0x80 ? '1' : '0');
}
buffer[pos++] = value;
}
}
pos_0--;
offset1++;
int t = (frame == 0) ? times * 3: times;
for (int j = 0; j < t; j++) {
draw_char(buffer);
}
}
}
void loop() {
char message[MSG_LEN];
char last_char = ' ';
int index = 0;
int is_marquee = 0;
Serial.print('1');
while (index < MSG_LEN - 1 && last_char != '\0') {
if (Serial.available()) {
last_char = Serial.read();
if (index == 0 && last_char == '~') {
message[index] = ' ';
is_marquee = 1;
} else {
message[index] = last_char;
}
index++;
}
}
Serial.print('0');
int len_message = strlen(message);
for (int i = 0; i < 2; i++) {
for (int j = 0; j < len_message; j++) {
if (is_marquee) {
// marquee
if (i == 1 && j == len_message -1) {
break;
}
int k1 = (int) message[j] - 32;
int k2 = (int) message[(j < len_message - 1) ? j + 1 : 0] - 32;
marquee_chars(charset[k1], charset[k2], 30);
} else {
// static, fixed
int k = (int) message[j] - 32;
fixed_char(charset[k], 100);
fixed_char(charset[0], 50); // space
}
}
}
}