#include <FrequencyTimer2.h>
//matrix 5x5
int temCol = 5; //no puede ser mas de 8
int temFil = 5; //no puede ser mas de 5
#define A { \
{1, 1, 1, 1, 1}, \
{1, 0, 0, 0, 1}, \
{1, 1, 1, 1, 1}, \
{1, 0, 0, 0, 1}, \
{1, 0, 0, 0, 1} \
}
#define B { \
{1, 1, 1, 1, 0}, \
{1, 0, 0, 0, 1}, \
{1, 1, 1, 1, 0}, \
{1, 0, 0, 0, 1}, \
{1, 1, 1, 1, 0} \
}
#define C { \
{1, 1, 1, 1, 1}, \
{1, 0, 0, 0, 0}, \
{1, 0, 0, 0, 0}, \
{1, 0, 0, 0, 0}, \
{1, 1, 1, 1, 1} \
}
#define D { \
{1, 1, 1, 1, 0}, \
{1, 0, 0, 0, 1}, \
{1, 0, 0, 0, 1}, \
{1, 0, 0, 0, 1}, \
{1, 1, 1, 1, 0} \
}
#define E { \
{1, 1, 1, 1, 1}, \
{1, 0, 0, 0, 0}, \
{1, 1, 1, 1, 1}, \
{1, 0, 0, 0, 0}, \
{1, 1, 1, 1, 1} \
}
#define F { \
{1, 1, 1, 1, 1}, \
{1, 0, 0, 0, 0}, \
{1, 1, 1, 1, 0}, \
{1, 0, 0, 0, 0}, \
{1, 0, 0, 0, 0} \
}
#define G { \
{1, 0, 1, 1, 1}, \
{1, 0, 0, 0, 0}, \
{1, 1, 1, 1, 1}, \
{1, 0, 0, 0, 1}, \
{1, 1, 1, 1, 1} \
}
#define H { \
{1, 0, 0, 0, 1}, \
{1, 0, 0, 0, 1}, \
{1, 1, 1, 1, 1}, \
{1, 0, 0, 0, 1}, \
{1, 0, 0, 0, 1} \
}
#define I { \
{1, 1, 1, 1, 1}, \
{0, 0, 1, 0, 0}, \
{0, 0, 1, 0, 0}, \
{0, 0, 1, 0, 0}, \
{1, 1, 1, 1, 1} \
}
#define J { \
{1, 1, 1, 1, 1}, \
{1, 0, 1, 0, 0}, \
{0, 0, 1, 0, 0}, \
{0, 0, 1, 0, 0}, \
{1, 1, 1, 0, 0} \
}
#define K { \
{1, 0, 0, 0, 1}, \
{1, 0, 0, 1, 0}, \
{1, 1, 1, 0, 0}, \
{1, 0, 0, 1, 0}, \
{1, 0, 0, 0, 1} \
}
#define L { \
{1, 0, 0, 0, 0}, \
{1, 0, 0, 0, 0}, \
{1, 0, 0, 0, 0}, \
{1, 0, 0, 0, 0}, \
{1, 1, 1, 1, 1} \
}
#define M { \
{1, 1, 0, 1, 1}, \
{1, 0, 1, 0, 1}, \
{1, 0, 0, 0, 1}, \
{1, 0, 0, 0, 1}, \
{1, 0, 0, 0, 1} \
}
#define N { \
{1, 0, 0, 0, 1}, \
{1, 1, 0, 0, 1}, \
{1, 0, 1, 0, 1}, \
{1, 0, 0, 1, 1}, \
{1, 0, 0, 0, 1} \
}
#define O { \
{1, 1, 1, 1, 1}, \
{1, 0, 0, 0, 1}, \
{1, 0, 0, 0, 1}, \
{1, 0, 0, 0, 1}, \
{1, 1, 1, 1, 1} \
}
#define P { \
{1, 1, 1, 1, 1}, \
{1, 0, 0, 0, 1}, \
{1, 1, 1, 1, 1}, \
{1, 0, 0, 0, 0}, \
{1, 0, 0, 0, 0} \
}
#define Q { \
{1, 1, 1, 1, 1}, \
{1, 0, 0, 0, 1}, \
{1, 0, 0, 0, 1}, \
{1, 0, 0, 1, 1}, \
{1, 1, 1, 1, 1} \
}
#define R { \
{1, 1, 1, 1, 0}, \
{1, 0, 0, 0, 1}, \
{1, 1, 1, 1, 0}, \
{1, 0, 0, 1, 0}, \
{1, 0, 0, 0, 1} \
}
#define S { \
{0, 1, 1, 1, 1}, \
{1, 0, 0, 0, 0}, \
{0, 1, 1, 1, 0}, \
{0, 0, 0, 0, 1}, \
{1, 1, 1, 1, 0} \
}
#define T { \
{1, 1, 1, 1, 1}, \
{0, 0, 1, 0, 0}, \
{0, 0, 1, 0, 0}, \
{0, 0, 1, 0, 0}, \
{0, 0, 1, 0, 0} \
}
#define U { \
{1, 0, 0, 0, 1}, \
{1, 0, 0, 0, 1}, \
{1, 0, 0, 0, 1}, \
{1, 0, 0, 0, 1}, \
{1, 1, 1, 1, 1} \
}
#define V { \
{1, 0, 0, 0, 1}, \
{1, 0, 0, 0, 1}, \
{1, 0, 0, 0, 1}, \
{0, 1, 0, 1, 0}, \
{0, 0, 1, 0, 0} \
}
#define W { \
{1, 0, 0, 0, 1}, \
{1, 0, 0, 0, 1}, \
{1, 0, 1, 0, 1}, \
{1, 1, 0, 1, 1}, \
{1, 0, 0, 0, 1} \
}
#define X { \
{1, 0, 0, 0, 1}, \
{0, 1, 0, 1, 0}, \
{0, 0, 1, 0, 0}, \
{0, 1, 0, 1, 0}, \
{1, 0, 0, 0, 1} \
}
#define Y { \
{1, 0, 0, 0, 1}, \
{1, 0, 0, 0, 1}, \
{0, 1, 1, 1, 0}, \
{0, 0, 1, 0, 0}, \
{0, 0, 1, 0, 0} \
}
#define Z { \
{1, 1, 1, 1, 1}, \
{1, 0, 0, 1, 0}, \
{0, 0, 1, 0, 0}, \
{0, 1, 0, 0, 1}, \
{1, 1, 1, 1, 1} \
}
#define blanco { \
{0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0} \
}
int col2 = 0;
int tiempoEspera = 0;
const int numLetras = 27;
int letras [numLetras][5][5] = {
A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,blanco
};
//matrix 5x8
const int numCol = 5;
const int numFil = 8;
int matrixLeds[numFil][numCol];
//filas
const int fil[numFil] = {
10,14,9,12,2,8,3,6};
//columnas
const int col[numCol] = {
13,4,5,11,7};
//http://playground.arduino.cc/ArduinoNotebookTraduccion/Appendix4
void setup(){
for(int i = 0; i < numFil; i++){
pinMode(fil[i], OUTPUT);
digitalWrite(fil[i],LOW);
}
for(int i = 0; i < numCol; i++){
pinMode(col[i], OUTPUT);
digitalWrite(col[i],LOW);
}
Serial.begin(9600);
tiempoEspera = 150;
FrequencyTimer2::disable();
FrequencyTimer2::setPeriod(2000);
FrequencyTimer2::setOnOverflow(display);
}
void loop(){
if(Serial.available() > 0){
byte dato = Serial.read();
//si el dato esta entre A-Z o a-z
if((64 < dato && dato < 91) || (96 < dato && dato < 123)){
//pasamos a mayuscula el caracter
byte caracterMayuscula = toUpperCase(dato);
//cargamos el caracter en la matrix matrixLeds
//y movemos cada pixel de posicion
moveCharater(caracterMayuscula-65);
}else
//si hay un espacio
if(dato == 32){
moveCharater(numLetras-1);
}
}else{
moveCharater(numLetras-1);
}
}
void obtenerCaracter(int posicionCaracter){
int posicion = numFil - temCol;
for(int j = 0; j < temFil; j++){
for(int i = 0; i < temCol; i++){
matrixLeds[i+posicion][temCol-1-j] = letras[posicionCaracter][j][i];
}
}
}
void siguinteCaracter(int posicionCaracter, int temFila){
int matrixTem[temFil][temCol];
for(int i = 0; i < temFil; i++){
for(int j = 0; j < temCol; j++){
matrixTem[j][4-i] = letras[posicionCaracter][i][j];
}
}
for (int j = 0; j < numCol; j++){
matrixLeds[numFil-1][j] = matrixTem[temFila][j];
}
}
void moveCharater(int posicionCaracter){
int temFila = 0;
do{
for(int i = 0; i < numCol; i++){
for(int j = 0; j < numFil-1; j++){
matrixLeds[j][i] = matrixLeds[j+1][i];
}
}
siguinteCaracter(posicionCaracter, temFila);
delay(tiempoEspera);
temFila++;
}while(temFila < numFil);
}
void display()
{
// Turn whole previous column off:
digitalWrite(col[col2], HIGH);
col2++;
if (col2 == 5) {
col2 = 0;
}
for (int row2 = 0; row2 < 8; row2++) {
if (matrixLeds[row2][col2] == 1) {
digitalWrite(fil[row2], HIGH); // Turn on this led
}
else {
digitalWrite(fil[row2], LOW); // Turn off this led
}
}
// Turn whole column on at once (for equal lighting times):
digitalWrite(col[col2], LOW);
}