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