Advertisement
Guest User

I_WIN Jason Kerry Kim

a guest
Oct 9th, 2012
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Show messages on an 8x8 led matrix,
  3.  * scrolling from right to left.
  4.  *
  5.  * Uses FrequencyTimer2 library to
  6.  * constantly run an interrupt routine
  7.  * at a specified frequency. This
  8.  * refreshes the display without the
  9.  * main loop having to do anything.
  10.  *
  11.  */
  12.  
  13. #include <FrequencyTimer2.h>
  14.  
  15.  
  16. #define A  { \
  17.     {0, 0, 0, 1, 1, 0, 0, 0}, \
  18.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  19.     {0, 1, 0, 0, 0, 0, 1, 0}, \
  20.     {0, 1, 0, 0, 0, 0, 1, 0}, \
  21.     {0, 1, 1, 1, 1, 1, 1, 0}, \
  22.     {0, 1, 0, 0, 0, 0, 1, 0}, \
  23.     {0, 1, 0, 0, 0, 0, 1, 0}, \
  24.     {0, 1, 0, 0, 0, 0, 1, 0}  \
  25. }
  26.  
  27. #define B { \
  28.     {0, 0, 1, 1, 0, 0, 0, 0},  \
  29.     {0, 0, 1, 0, 1, 0, 0, 0}, \
  30.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  31.     {0, 0, 1, 0, 1, 0, 0, 0}, \
  32.     {0, 0, 1, 1, 1, 0, 0, 0}, \
  33.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  34.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  35.     {0, 0, 1, 1, 1, 0, 0, 0} \
  36. }
  37.  
  38. #define C { \
  39.     {0, 0, 0, 1, 1, 0, 0, 0},  \
  40.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  41.     {0, 0, 1, 0, 0, 0, 0, 0}, \
  42.     {0, 0, 1, 0, 0, 0, 0, 0}, \
  43.     {0, 0, 1, 0, 0, 0, , 0}, \
  44.     {0, 0, 1, 0, 0, 0, , 0}, \
  45.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  46.     {0, 0, 0, 1, 1, 0, 0, 0} \
  47. }
  48.  
  49. #define D { \
  50.     {0, 0, 1, 1, 0, 0, 0, 0},  \
  51.     {0, 0, 1, 0, 1, 0, 0, 0}, \
  52.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  53.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  54.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  55.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  56.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  57.     {0, 0, 1, 1, 1, 0, 0, 0} \
  58. }
  59.  
  60. #define E { \
  61.     {0, 0, 1, 1, 1, 1, 0, 0},  \
  62.     {0, 0, 1, 0, 0, 0, 0, 0}, \
  63.     {0, 0, 1, 0, 0, 0, 0, 0}, \
  64.     {0, 0, 1, 1, 1, 0, 0, 0}, \
  65.     {0, 0, 1, 0, 0, 0, 0, 0}, \
  66.     {0, 0, 1, 0, 0, 0, 0, 0}, \
  67.     {0, 0, 1, 0, 0, 0, 0, 0}, \
  68.     {0, 0, 1, 1, 1, 1, 0, 0} \
  69. }
  70.  
  71. #define F { \
  72.     {0, 0, 1, 1, 1, 1, 0, 0},  \
  73.     {0, 0, 1, 0, 0, 0, 0, 0}, \
  74.     {0, 0, 1, 0, 0, 0, 0, 0}, \
  75.     {0, 0, 1, 1, 1, 0, 0, 0}, \
  76.     {0, 0, 1, 0, 0, 0, 0, 0}, \
  77.     {0, 0, 1, 0, 0, 0, 0, 0}, \
  78.     {0, 0, 1, 0, 0, 0, 0, 0}, \
  79.     {0, 0, 1, 0, 0, 0, 0, 0} \
  80. }
  81.  
  82. #define G { \
  83.     {0, 0, 0, 1, 1, 0, 0, 0},  \
  84.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  85.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  86.     {0, 0, 1, 0, 0, 0, 0, 0}, \
  87.     {0, 0, 1, 0, 1, 1, 0, 0}, \
  88.     {0, 0, 1, 0, 0, 1, , 0}, \
  89.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  90.     {0, 0, 0, 1, 1, 1, 0, 0} \
  91. }
  92.  
  93. #define H { \
  94.     {0, 0, 1, 0, 0, 1, 0, 0},  \
  95.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  96.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  97.     {0, 0, 1, 1, 1, 1, 0, 0}, \
  98.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  99.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  100.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  101.     {0, 0, 1, 0, 0, 1, 0, 0} \
  102. }
  103.  
  104. #define I { \
  105.     {0, 0, 0, 1, 1, 0, 0, 0},  \
  106.     {0, 0, 0, 1, 1, 0, 0, 0}, \
  107.     {0, 0, 0, 1, 1, 0, 0, 0}, \
  108.     {0, 0, 0, 1, 1, 0, 0, 0}, \
  109.     {0, 0, 0, 1, 1, 0, 0, 0}, \
  110.     {0, 0, 0, 1, 1, 0, 0, 0}, \
  111.     {0, 0, 0, 1, 1, 0, 0, 0}, \
  112.     {0, 0, 0, 1, 1, 0, 0, 0} \
  113. }
  114.  
  115. #define J { \
  116.     {0, 0, 0, 0, 0, 1, 0, 0}, \
  117.     {0, 0, 0, 0, 0, 1, 0, 0}, \
  118.     {0, 0, 0, 0, 0, 1, 0, 0}, \
  119.     {0, 0, 0, 0, 0, 1, 0, 0}, \
  120.     {0, 0, 0, 0, 0, 1, 0, 0}, \
  121.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  122.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  123.     {0, 0, 0, 1, 1, 0, 0, 0}  \
  124. }
  125.  
  126. #define K { \
  127.     {0, 0, 1, 0, 0, 1, 0, 0},  \
  128.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  129.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  130.     {0, 0, 1, 1, 1, 0, 0, 0}, \
  131.     {0, 0, 1, 0, 1, 0, 0, 0}, \
  132.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  133.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  134.     {0, 0, 1, 0, 0, 1, 0, 0} \
  135. }
  136.  
  137. #define L { \
  138.     {0, 0, 1, 0, 0, 0, 0, 0},  \
  139.     {0, 0, 1, 0, 0, 0, 0, 0}, \
  140.     {0, 0, 1, 0, 0, 0, 0, 0}, \
  141.     {0, 0, 1, 0, 0, 0, 0, 0}, \
  142.     {0, 0, 1, 0, 0, 0, 0, 0}, \
  143.     {0, 0, 1, 0, 0, 0, 0, 0}, \
  144.     {0, 0, 1, 0, 0, 0, 0, 0}, \
  145.     {0, 0, 1, 1, 1, 1, 0, 0} \
  146. }
  147.  
  148. #define M { \
  149.     {0, 1, 1, 0, 0, 0, 1, 0},  \
  150.     {0, 1, 0, 1, 0, 1, 1, 0}, \
  151.     {0, 1, 0, 1, 1, 0, 1, 0}, \
  152.     {0, 1, 0, 1, 1, 0, 1, 0}, \
  153.     {0, 1, 0, 1, 1, 0, 1, 0}, \
  154.     {0, 1, 0, 1, 1, 0, 1, 0}, \
  155.     {0, 1, 0, 0, 0, 0, 1, 0}, \
  156.     {0, 1, 0, 0, 0, 0, 1, 0} \
  157. }
  158.  
  159. #define N { \
  160.     {0, 1, 0, 0, 0, 0, 1, 0}, \
  161.     {0, 1, 1, 0, 0, 0, 1, 0}, \
  162.     {0, 1, 0, 1, 0, 0, 1, 0}, \
  163.     {0, 1, 0, 0, 1, 0, 1, 0}, \
  164.     {0, 1, 0, 0, 0, 1, 1, 0}, \
  165.     {0, 1, 0, 0, 0, 0, 1, 0}, \
  166.     {0, 1, 0, 0, 0, 0, 1, 0}, \
  167.     {0, 1, 0, 0, 0, 0, 1, 0}  \
  168. }
  169.  
  170. #define O { \
  171.     {0, 0, 0, 1, 1, 0, 0, 0}, \
  172.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  173.     {0, 1, 0, 0, 0, 0, 1, 0}, \
  174.     {0, 1, 0, 0, 0, 0, 1, 0}, \
  175.     {0, 1, 0, 0, 0, 0, 1, 0}, \
  176.     {0, 1, 0, 0, 0, 0, 1, 0}, \
  177.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  178.     {0, 0, 0, 1, 1, 0, 0, 0}  \
  179. }
  180.  
  181. #define P { \
  182.     {0, 0, 1, 1, 1, 0, 0, 0},  \
  183.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  184.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  185.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  186.     {0, 0, 1, 1, 1, 0, 0, 0}, \
  187.     {0, 0, 1, 0, 0, 0, 0, 0}, \
  188.     {0, 0, 1, 0, 0, 0, 0, 0}, \
  189.     {0, 0, 1, 0, 0, 0, 0, 0} \
  190. }
  191.  
  192. #define Q { \
  193.     {0, 0, 0, 1, 1, 0, 0, 0}, \
  194.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  195.     {0, 1, 0, 0, 0, 0, 1, 0}, \
  196.     {0, 1, 0, 0, 0, 0, 1, 0}, \
  197.     {0, 1, 0, 0, 0, 0, 1, 0}, \
  198.     {0, 1, 0, 0, 1, 0, 1, 0}, \
  199.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  200.     {0, 0, 0, 1, 1, 0, 1, 0}  \
  201. }
  202.  
  203. #define R { \
  204.     {0, 0, 1, 1, 1, 0, 0, 0},  \
  205.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  206.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  207.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  208.     {0, 0, 1, 1, 1, 0, 0, 0}, \
  209.     {0, 0, 1, 0, 1, 0, 0, 0}, \
  210.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  211.     {0, 0, 1, 0, 0, 1, 0, 0} \
  212. }
  213.  
  214. #define S { \
  215.     {0, 0, 0, 1, 1, 1, 1, 0}, \
  216.     {0, 0, 1, 0, 0, 0, 0, 0}, \
  217.     {0, 0, 1, 0, 0, 0, 0, 0}, \
  218.     {0, 0, 1, 0, 0, 0, 0, 0}, \
  219.     {0, 0, 0, 1, 1, 1, 0, 0}, \
  220.     {0, 0, 0, 0, 0, 0, 1, 0}, \
  221.     {0, 0, 0, 0, 0, 0, 1, 0}, \
  222.     {0, 0, 1, 1, 1, 1, 0, 0}  \
  223. }
  224.  
  225. #define T { \
  226.     {0, 1, 1, 1, 1, 1, 1, 0},  \
  227.     {0, 0, 0, 1, 1, 0, 0, 0}, \
  228.     {0, 0, 0, 1, 1, 0, 0, 0}, \
  229.     {0, 0, 0, 1, 1, 0, 0, 0}, \
  230.     {0, 0, 0, 1, 1, 0, 0, 0}, \
  231.     {0, 0, 0, 1, 1, 0, 0, 0}, \
  232.     {0, 0, 0, 1, 1, 0, 0, 0}, \
  233.     {0, 0, 0, 1, 1, 0, 0, 0} \
  234. }
  235.  
  236. #define U { \
  237.     {0, 0, 1, 0, 0, 1, 0, 0},  \
  238.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  239.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  240.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  241.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  242.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  243.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  244.     {0, 0, 0, 1, 1, 0, 0, 0} \
  245. }
  246.  
  247. #define V { \
  248.     {0, 0, 1, 0, 0, 0, 1, 0},  \
  249.     {0, 0, 1, 0, 0, 0, 1, 0}, \
  250.     {0, 0, 1, 0, 0, 0, 1, 0}, \
  251.     {0, 0, 1, 0, 0, 0, 1, 0}, \
  252.     {0, 0, 1, 0, 0, 0, 1, 0}, \
  253.     {0, 0, 1, 0, 0, 0, 1, 0}, \
  254.     {0, 0, 0, 1, 0, 1, 0, 0}, \
  255.     {0, 0, 0, 0, 1, 0, 0, 0} \
  256. }
  257.  
  258. #define W { \
  259.     {0, 1, 0, 0, 0, 0, 1, 0},  \
  260.     {0, 1, 0, 0, 0, 0, 1, 0}, \
  261.     {0, 1, 0, 0, 0, 0, 1, 0}, \
  262.     {0, 1, 0, 0, 0, 0, 1, 0}, \
  263.     {0, 1, 0, 1, 1, 0, 1, 0}, \
  264.     {0, 1, 0, 1, 1, 0, 1, 0}, \
  265.     {0, 1, 0, 1, 1, 0, 1, 0}, \
  266.     {0, 0, 1, 0, 0, 1, 0, 0} \
  267. }
  268.  
  269. #define X { \
  270.     {0, 1, 0, 0, 0, 0, 1, 0},  \
  271.     {0, 1, 0, 0, 0, 0, 1, 0}, \
  272.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  273.     {0, 0, 0, 1, 1, 0, 0, 0}, \
  274.     {0, 0, 0, 1, 1, 0, 0, 0}, \
  275.     {0, 0, 0, 0, 0, 1, 0, 0}, \
  276.     {0, 0, 1, 0, 0, 0, 1, 0}, \
  277.     {0, 1, 0, 0, 0, 0, 1, 0} \
  278. }
  279.  
  280. #define Y { \
  281.     {0, 0, 1, 0, 0, 1, 0, 0},  \
  282.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  283.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  284.     {0, 0, 1, 0, 0, 1, 0, 0}, \
  285.     {0, 0, 0, 1, 1, 0, 0, 0}, \
  286.     {0, 0, 0, 1, 1, 0, 0, 0}, \
  287.     {0, 0, 0, 1, 1, 0, 0, 0}, \
  288.     {0, 0, 0, 1, 1, 0, 0, 0} \
  289. }
  290.  
  291. #define Z { \
  292.     {0, 1, 1, 1, 1, 1, 1, 0},  \
  293.     {0, 0, 0, 0, 0, 1, 0, 0}, \
  294.     {0, 0, 0, 0, 1, 0, 0, 0}, \
  295.     {0, 0, 0, 1, 0, 0, 0, 0}, \
  296.     {0, 0, 1, 0, 0, 0, 0, 0}, \
  297.     {0, 1, 0, 0, 0, 0, 0, 0}, \
  298.     {0, 1, 0, 0, 0, 0, 0, 0}, \
  299.     {0, 1, 1, 1, 1, 1, 1, 0} \
  300. }
  301.  
  302. #define SPACE { \
  303.     {0, 0, 0, 0, 0, 0, 0, 0},  \
  304.     {0, 0, 0, 0, 0, 0, 0, 0}, \
  305.     {0, 0, 0, 0, 0, 0, 0, 0}, \
  306.     {0, 0, 0, 0, 0, 0, 0, 0}, \
  307.     {0, 0, 0, 0, 0, 0, 0, 0}, \
  308.     {0, 0, 0, 0, 0, 0, 0, 0}, \
  309.     {0, 0, 0, 0, 0, 0, 0, 0}, \
  310.     {0, 0, 0, 0, 0, 0, 0, 0} \
  311. }
  312.  
  313. #define BLOCK { \
  314.     {1, 1, 1, 1, 1, 1, 1, 1}, \
  315.     {1, 1, 1, 1, 1, 1, 1, 1}, \
  316.     {1, 1, 1, 1, 1, 1, 1, 1}, \
  317.     {1, 1, 1, 1, 1, 1, 1, 1}, \
  318.     {1, 1, 1, 1, 1, 1, 1, 1}, \
  319.     {1, 1, 1, 1, 1, 1, 1, 1}, \
  320.     {1, 1, 1, 1, 1, 1, 1, 1}, \
  321.     {1, 1, 1, 1, 1, 1, 1, 1}  \
  322. }
  323.  
  324. byte col = 0;
  325. byte leds[8][8];
  326.  
  327. // pin[xx] on led matrix connected to nn on Arduino (-1 is dummy to make array start at pos 1)
  328. int pins[17]= {-1, 5, 4, 3, 2, 14, 15, 16, 17, 13, 12, 11, 10, 9, 8, 7, 6};
  329.  
  330. // col[xx] of leds = pin yy on led matrix
  331. int cols[8] = {pins[13], pins[3], pins[4], pins[10], pins[06], pins[11], pins[15], pins[16]};
  332.  
  333. // row[xx] of leds = pin yy on led matrix
  334. int rows[8] = {pins[9], pins[14], pins[8], pins[12], pins[1], pins[7], pins[2], pins[5]};
  335.  
  336. int scrollSpeed;
  337.  
  338. const int numPatterns = 6;
  339. byte patterns[numPatterns][8][8] = {
  340.   I,SPACE,W,I,N,N
  341. };
  342.  
  343. int pattern = 0;
  344.  
  345. void setup() {
  346.   // sets the pins as output
  347.   for (int i = 1; i <= 16; i++) {
  348.     pinMode(pins[i], OUTPUT);
  349.   }
  350.  
  351.   // set up cols and rows
  352.   for (int i = 1; i <= 8; i++) {
  353.     digitalWrite(cols[i - 1], LOW);
  354.   }
  355.  
  356.   for (int i = 1; i <= 8; i++) {
  357.     digitalWrite(rows[i - 1], LOW);
  358.   }
  359.  
  360.   clearLeds();
  361.  
  362.   // Turn off toggling of pin 11
  363.   FrequencyTimer2::disable();
  364.   // Set refresh rate (interrupt timeout period)
  365.   FrequencyTimer2::setPeriod(2000);
  366.   // Set interrupt routine to be called
  367.   FrequencyTimer2::setOnOverflow(display);
  368.  
  369.   setPattern(pattern);
  370. }
  371.  
  372. void loop() {
  373.     pattern = ++pattern % numPatterns;
  374.     scrollSpeed = 60;
  375.     slidePattern(pattern, scrollSpeed);
  376.     // THIS IS TO REVERSE THE ORDER THAT THE CHARACTERS ARE DISPLAYED
  377.     //slidePattern(numPatterns - pattern -1, 60);
  378. }
  379.  
  380. void clearLeds() {
  381.   // Clear display array
  382.   for (int i = 0; i < 8; i++) {
  383.     for (int j = 0; j < 8; j++) {
  384.       leds[i][j] = 0;
  385.     }
  386.   }
  387. }
  388.  
  389. void setPattern(int pattern) {
  390.   for (int i = 0; i < 8; i++) {
  391.     for (int j = 0; j < 8; j++) {
  392.       leds[i][j] = patterns[pattern][i][j];
  393.     }
  394.   }
  395. }
  396.  
  397. void slidePattern(int pattern, int del) {
  398.   for (int l = 0; l < 8; l++) {
  399.     for (int i = 0; i < 7; i++) {
  400.       for (int j = 0; j < 8; j++) {
  401.         leds[j][i] = leds[j][i+1];
  402.       }
  403.     }
  404.     for (int j = 0; j < 8; j++) {
  405.       leds[j][7] = patterns[pattern][j][0 + l];
  406.     }
  407.     delay(del);
  408.   }
  409. }
  410.  
  411. // Interrupt routine
  412. void display() {
  413.   digitalWrite(cols[col], HIGH);  // Turn whole previous column off
  414.   col++;
  415.   if (col == 8) {
  416.     col = 0;
  417.   }
  418.   for (int row = 0; row < 8; row++) {
  419.     if (leds[col][7 - row] == 1) {  
  420.                                       // This Value used to be LOW, I switched it to HIGH for
  421.       digitalWrite(rows[row], HIGH);  // Our LED MATRIX
  422.                                       // Turn on this led
  423.     }
  424.     else {  
  425.                                     // This Value used to be HIGH, I switched it to LOW for
  426.       digitalWrite(rows[row], LOW); // Our LED MATRIX
  427.                                     // Turn on this led
  428.     }
  429.   }
  430.   digitalWrite(cols[col], LOW); // Turn whole column on at once (for equal lighting times)
  431. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement