Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. //Se incluye la libreria FrequencyTimer2
  2. #include <FrequencyTimer2.h>
  3.  
  4. //matrix 5x5
  5. //se declara la variable temCol de tipo entero inicializada en 5
  6. int temCol = 5;
  7. //se declara la variable temFil de tipo entero inicializada en 5
  8. int temFil = 5;
  9.  
  10. //se definen las matrices de letras [A-Z]
  11. #define A { \
  12. {1, 1, 1, 1, 1}, \
  13. {1, 0, 0, 0, 1}, \
  14. {1, 1, 1, 1, 1}, \
  15. {1, 0, 0, 0, 1}, \
  16. {1, 0, 0, 0, 1} \
  17. }
  18.  
  19. #define B { \
  20. {1, 1, 1, 1, 0}, \
  21. {1, 0, 0, 0, 1}, \
  22. {1, 1, 1, 1, 0}, \
  23. {1, 0, 0, 0, 1}, \
  24. {1, 1, 1, 1, 0} \
  25. }
  26.  
  27. #define C { \
  28. {1, 1, 1, 1, 1}, \
  29. {1, 0, 0, 0, 0}, \
  30. {1, 0, 0, 0, 0}, \
  31. {1, 0, 0, 0, 0}, \
  32. {1, 1, 1, 1, 1} \
  33. }
  34.  
  35. #define D { \
  36. {1, 1, 1, 1, 0}, \
  37. {1, 0, 0, 0, 1}, \
  38. {1, 0, 0, 0, 1}, \
  39. {1, 0, 0, 0, 1}, \
  40. {1, 1, 1, 1, 0} \
  41. }
  42.  
  43. #define E { \
  44. {1, 1, 1, 1, 1}, \
  45. {1, 0, 0, 0, 0}, \
  46. {1, 1, 1, 1, 1}, \
  47. {1, 0, 0, 0, 0}, \
  48. {1, 1, 1, 1, 1} \
  49. }
  50.  
  51. #define F { \
  52. {1, 1, 1, 1, 1}, \
  53. {1, 0, 0, 0, 0}, \
  54. {1, 1, 1, 1, 0}, \
  55. {1, 0, 0, 0, 0}, \
  56. {1, 0, 0, 0, 0} \
  57. }
  58.  
  59. #define G { \
  60. {1, 0, 1, 1, 1}, \
  61. {1, 0, 0, 0, 0}, \
  62. {1, 1, 1, 1, 1}, \
  63. {1, 0, 0, 0, 1}, \
  64. {1, 1, 1, 1, 1} \
  65. }
  66.  
  67. #define H { \
  68. {1, 0, 0, 0, 1}, \
  69. {1, 0, 0, 0, 1}, \
  70. {1, 1, 1, 1, 1}, \
  71. {1, 0, 0, 0, 1}, \
  72. {1, 0, 0, 0, 1} \
  73. }
  74.  
  75. #define I { \
  76. {1, 1, 1, 1, 1}, \
  77. {0, 0, 1, 0, 0}, \
  78. {0, 0, 1, 0, 0}, \
  79. {0, 0, 1, 0, 0}, \
  80. {1, 1, 1, 1, 1} \
  81. }
  82.  
  83. #define J { \
  84. {1, 1, 1, 1, 1}, \
  85. {1, 0, 1, 0, 0}, \
  86. {0, 0, 1, 0, 0}, \
  87. {0, 0, 1, 0, 0}, \
  88. {1, 1, 1, 0, 0} \
  89. }
  90.  
  91. #define K { \
  92. {1, 0, 0, 0, 1}, \
  93. {1, 0, 0, 1, 0}, \
  94. {1, 1, 1, 0, 0}, \
  95. {1, 0, 0, 1, 0}, \
  96. {1, 0, 0, 0, 1} \
  97. }
  98.  
  99. #define L { \
  100. {1, 0, 0, 0, 0}, \
  101. {1, 0, 0, 0, 0}, \
  102. {1, 0, 0, 0, 0}, \
  103. {1, 0, 0, 0, 0}, \
  104. {1, 1, 1, 1, 1} \
  105. }
  106.  
  107. #define M { \
  108. {1, 1, 0, 1, 1}, \
  109. {1, 0, 1, 0, 1}, \
  110. {1, 0, 0, 0, 1}, \
  111. {1, 0, 0, 0, 1}, \
  112. {1, 0, 0, 0, 1} \
  113. }
  114.  
  115. #define N { \
  116. {1, 0, 0, 0, 1}, \
  117. {1, 1, 0, 0, 1}, \
  118. {1, 0, 1, 0, 1}, \
  119. {1, 0, 0, 1, 1}, \
  120. {1, 0, 0, 0, 1} \
  121. }
  122.  
  123. #define O { \
  124. {1, 1, 1, 1, 1}, \
  125. {1, 0, 0, 0, 1}, \
  126. {1, 0, 0, 0, 1}, \
  127. {1, 0, 0, 0, 1}, \
  128. {1, 1, 1, 1, 1} \
  129. }
  130.  
  131. #define P { \
  132. {1, 1, 1, 1, 1}, \
  133. {1, 0, 0, 0, 1}, \
  134. {1, 1, 1, 1, 1}, \
  135. {1, 0, 0, 0, 0}, \
  136. {1, 0, 0, 0, 0} \
  137. }
  138.  
  139. #define Q { \
  140. {1, 1, 1, 1, 1}, \
  141. {1, 0, 0, 0, 1}, \
  142. {1, 0, 0, 0, 1}, \
  143. {1, 0, 0, 1, 1}, \
  144. {1, 1, 1, 1, 1} \
  145. }
  146.  
  147. #define R { \
  148. {1, 1, 1, 1, 0}, \
  149. {1, 0, 0, 0, 1}, \
  150. {1, 1, 1, 1, 0}, \
  151. {1, 0, 0, 1, 0}, \
  152. {1, 0, 0, 0, 1} \
  153. }
  154.  
  155. #define S { \
  156. {0, 1, 1, 1, 1}, \
  157. {1, 0, 0, 0, 0}, \
  158. {0, 1, 1, 1, 0}, \
  159. {0, 0, 0, 0, 1}, \
  160. {1, 1, 1, 1, 0} \
  161. }
  162.  
  163. #define T { \
  164. {1, 1, 1, 1, 1}, \
  165. {0, 0, 1, 0, 0}, \
  166. {0, 0, 1, 0, 0}, \
  167. {0, 0, 1, 0, 0}, \
  168. {0, 0, 1, 0, 0} \
  169. }
  170.  
  171. #define U { \
  172. {1, 0, 0, 0, 1}, \
  173. {1, 0, 0, 0, 1}, \
  174. {1, 0, 0, 0, 1}, \
  175. {1, 0, 0, 0, 1}, \
  176. {1, 1, 1, 1, 1} \
  177. }
  178.  
  179. #define V { \
  180. {1, 0, 0, 0, 1}, \
  181. {1, 0, 0, 0, 1}, \
  182. {1, 0, 0, 0, 1}, \
  183. {0, 1, 0, 1, 0}, \
  184. {0, 0, 1, 0, 0} \
  185. }
  186.  
  187. #define W { \
  188. {1, 0, 0, 0, 1}, \
  189. {1, 0, 0, 0, 1}, \
  190. {1, 0, 1, 0, 1}, \
  191. {1, 1, 0, 1, 1}, \
  192. {1, 0, 0, 0, 1} \
  193. }
  194.  
  195. #define X { \
  196. {1, 0, 0, 0, 1}, \
  197. {0, 1, 0, 1, 0}, \
  198. {0, 0, 1, 0, 0}, \
  199. {0, 1, 0, 1, 0}, \
  200. {1, 0, 0, 0, 1} \
  201. }
  202.  
  203. #define Y { \
  204. {1, 0, 0, 0, 1}, \
  205. {1, 0, 0, 0, 1}, \
  206. {0, 1, 1, 1, 0}, \
  207. {0, 0, 1, 0, 0}, \
  208. {0, 0, 1, 0, 0} \
  209. }
  210.  
  211. #define Z { \
  212. {1, 1, 1, 1, 1}, \
  213. {1, 0, 0, 1, 0}, \
  214. {0, 0, 1, 0, 0}, \
  215. {0, 1, 0, 0, 1}, \
  216. {1, 1, 1, 1, 1} \
  217. }
  218.  
  219. #define blanco { \
  220. {0, 0, 0, 0, 0}, \
  221. {0, 0, 0, 0, 0}, \
  222. {0, 0, 0, 0, 0}, \
  223. {0, 0, 0, 0, 0}, \
  224. {0, 0, 0, 0, 0} \
  225. }
  226.  
  227. //se declara la variable col2 de tipo intero enicializada en 0
  228. int col2 = 0;
  229. //se declara la variable tiempoEspera de tipo entero inicializada en 150
  230. int tiempoEspera = 150;
  231. //se declara la variable numLetras de tipo entero inicializada en 27
  232. const int numLetras = 27;
  233. //se declara la variable letras de tipo matrix de entero
  234. int letras [numLetras][5][5] = {
  235.   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
  236. };
  237.  
  238. //matrix 5x8
  239. //se declara la variable numCol de tipo entero inicializada en 5
  240. const int numCol = 5;
  241. //se declara la variable numFil de tipo entero inicializada en 8
  242. const int numFil = 8;
  243. //se declara la variable matrixLeds de tipo matrix de entero
  244. int matrixLeds[numFil][numCol];
  245.  
  246. //filas
  247. //se declara la variable constante fil de tipo vector de entero
  248. const int fil[numFil] = {
  249.   10,14,9,12,2,8,3,6};
  250.  
  251. //columnas
  252. //se declara la variable constante col de tipo vector de entero inicializada en 5
  253. const int col[numCol] = {
  254.   13,4,5,11,7};
  255.  
  256. void setup(){  
  257.   for(int i = 0; i < numFil; i++) {
  258.     //pines de salida
  259.     pinMode(fil[i], OUTPUT);
  260.     //Se apaga el led,
  261.     digitalWrite(fil[i],LOW);
  262.   }
  263.  
  264.   for(int i = 0; i < numCol; i++) {
  265.     //pines de salida
  266.     pinMode(col[i], OUTPUT);
  267.     //Se apaga el led,
  268.     digitalWrite(col[i],LOW);  
  269.   }
  270.   //comunicacion serial a 9600bps
  271.   Serial.begin(9600);  
  272.  
  273.   FrequencyTimer2::disable();
  274.   FrequencyTimer2::setPeriod(2000);
  275.   FrequencyTimer2::setOnOverflow(display);  
  276. }
  277.  
  278. void loop(){  
  279.    if(Serial.available() > 0) {
  280.      byte dato = Serial.read();
  281.      //si el dato esta entre A-Z o a-z
  282.      if((64 < dato && dato < 91) || (96 < dato && dato < 123)){
  283.        //pasamos a mayuscula el caracter
  284.        byte caracterMayuscula = toUpperCase(dato);
  285.        //cargamos el caracter en la matrix matrixLeds
  286.        //y movemos cada pixel de posicion
  287.        moveCharater(caracterMayuscula-65);      
  288.      } else
  289.        //si hay un espacio
  290.        if(dato == 32){
  291.          moveCharater(numLetras-1);
  292.        }
  293.    } else {
  294.      moveCharater(numLetras-1);
  295.    }  
  296. }
  297.  
  298. void obtenerCaracter(int posicionCaracter){
  299.    int posicion = numFil - temCol;  
  300.    for(int j = 0; j < temFil; j++) {
  301.      for(int i = 0; i < temCol; i++) {
  302.        matrixLeds[i+posicion][temCol-1-j] = letras[posicionCaracter][j][i];      
  303.      }    
  304.   }
  305. }
  306.  
  307. void siguinteCaracter(int posicionCaracter, int temFila){
  308.   int matrixTem[temFil][temCol];
  309.  
  310.   for(int i = 0; i < temFil; i++) {
  311.      for(int j = 0; j < temCol; j++) {
  312.        matrixTem[j][4-i] = letras[posicionCaracter][i][j];
  313.      }
  314.   }
  315.  
  316.   for (int j = 0; j < numCol; j++){
  317.     matrixLeds[numFil-1][j] = matrixTem[temFila][j];
  318.   }
  319. }
  320.  
  321. void moveCharater(int posicionCaracter){  
  322.   int temFila = 0;
  323.  
  324.   do{      
  325.     for(int i = 0; i < numCol; i++) {
  326.       for(int j = 0; j < numFil-1; j++) {
  327.         matrixLeds[j][i] = matrixLeds[j+1][i];
  328.       }
  329.     }    
  330.     siguinteCaracter(posicionCaracter, temFila);    
  331.     delay(tiempoEspera);    
  332.    
  333.     temFila++;    
  334.   } while(temFila < numFil);  
  335. }
  336.  
  337. void display(){  
  338.    digitalWrite(col[col2], HIGH);
  339.    col2++;
  340.    
  341.    if (col2 == 5) {
  342.       col2 = 0;
  343.    }
  344.    for (int row2 = 0; row2 < 8; row2++) {
  345.       if (matrixLeds[row2][col2] == 1) {
  346.          digitalWrite(fil[row2], HIGH);
  347.       }
  348.       else {
  349.          digitalWrite(fil[row2], LOW);
  350.       }
  351.    }
  352.    digitalWrite(col[col2], LOW);
  353. }