Advertisement
filip710

prvi v2

May 6th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.80 KB | None | 0 0
  1.  
  2. #include "LedControl.h"
  3. #define BUTTON1 7
  4.  
  5. /*
  6.  Now we need a LedControl to work with.
  7.  * These pin numbers will probably not work with your hardware *
  8.  pin 12 is connected to the DataIn
  9.  pin 11 is connected to the CLK
  10.  pin 10 is connected to LOAD
  11.  We have only a single MAX72XX.
  12.  */
  13.  
  14. LedControl lc = LedControl(12, 11, 10, 1);
  15.  
  16. /* we always wait a bit between updates of the display */
  17. unsigned long delaytime = 500;
  18. byte six[8] = { B00000000,B11011011,B11011011,B00000000,B00000000,B11011011,B11011011,B00000000 };
  19. byte five[8] = { B00000000,B01100110,B01100110,B00011000,B00011000,B01100110,B01100110,B00000000 };
  20. byte four[8] = { B00000000,B01100110,B01100110,B00000000,B00000000,B01100110,B01100110,B00000000 };
  21. byte three[8] = { B11000000,B11000000,B00000000,B00011000,B00011000,B00000000,B00000011,B00000011 };
  22. byte two[8] = { B00000000,B00000000,B00000000,B01100110,B01100110,B00000000,B00000000,B00000000 };
  23. byte one[8] = { B00000000,B00000000,B00000000,B00011000,B00011000,B00000000,B00000000,B00000000 };
  24.  
  25. void setup() {
  26.     /*
  27.      The MAX72XX is in power-saving mode on startup,
  28.      we have to do a wakeup call
  29.      */
  30.     pinMode(BUTTON1, INPUT);
  31.     lc.shutdown(0, false);
  32.     /* Set the brightness to a medium values */
  33.     lc.setIntensity(0, 8);
  34.     /* and clear the display */
  35.     lc.clearDisplay(0);
  36. }
  37.  
  38. /*
  39.  This method will display the characters
  40.  (you need at least 7x7 leds to see the whole chars)
  41.  */
  42. void one1() {
  43.     /* here is the data for the characters */
  44.  
  45.     /* now display them one by one with a small delay */
  46.     lc.setRow(0, 0, one[0]);
  47.     lc.setRow(0, 1, one[1]);
  48.     lc.setRow(0, 2, one[2]);
  49.     lc.setRow(0, 3, one[3]);
  50.     lc.setRow(0, 4, one[4]);
  51.     lc.setRow(0, 5, one[5]);
  52.     lc.setRow(0, 6, one[6]);
  53.     lc.setRow(0, 7, one[7]);
  54.  
  55.     delay(delaytime);
  56. }
  57. void two2() {
  58.     /* here is the data for the characters */
  59.  
  60.     /* now display them one by one with a small delay */
  61.     lc.setRow(0, 0, two[0]);
  62.     lc.setRow(0, 1, two[1]);
  63.     lc.setRow(0, 2, two[2]);
  64.     lc.setRow(0, 3, two[3]);
  65.     lc.setRow(0, 4, two[4]);
  66.     lc.setRow(0, 5, two[5]);
  67.     lc.setRow(0, 6, two[6]);
  68.     lc.setRow(0, 7, two[7]);
  69.  
  70.     delay(delaytime);
  71. }
  72. void three3() {
  73.     /* here is the data for the characters */
  74.  
  75.     /* now display them one by one with a small delay */
  76.     lc.setRow(0, 0, three[0]);
  77.     lc.setRow(0, 1, three[1]);
  78.     lc.setRow(0, 2, three[2]);
  79.     lc.setRow(0, 3, three[3]);
  80.     lc.setRow(0, 4, three[4]);
  81.     lc.setRow(0, 5, three[5]);
  82.     lc.setRow(0, 6, three[6]);
  83.     lc.setRow(0, 7, three[7]);
  84.  
  85.     delay(delaytime);
  86. }
  87. void four4() {
  88.     /* here is the data for the characters */
  89.  
  90.     /* now display them four by four with a small delay */
  91.     lc.setRow(0, 0, four[0]);
  92.     lc.setRow(0, 1, four[1]);
  93.     lc.setRow(0, 2, four[2]);
  94.     lc.setRow(0, 3, four[3]);
  95.     lc.setRow(0, 4, four[4]);
  96.     lc.setRow(0, 5, four[5]);
  97.     lc.setRow(0, 6, four[6]);
  98.     lc.setRow(0, 7, four[7]);
  99.  
  100.     delay(delaytime);
  101. }
  102. void five5() {
  103.     /* here is the data for the characters */
  104.  
  105.     /* now display them five by five with a small delay */
  106.     lc.setRow(0, 0, five[0]);
  107.     lc.setRow(0, 1, five[1]);
  108.     lc.setRow(0, 2, five[2]);
  109.     lc.setRow(0, 3, five[3]);
  110.     lc.setRow(0, 4, five[4]);
  111.     lc.setRow(0, 5, five[5]);
  112.     lc.setRow(0, 6, five[6]);
  113.     lc.setRow(0, 7, five[7]);
  114.  
  115.     delay(delaytime);
  116. }
  117. void six6() {
  118.     /* here is the data for the characters */
  119.  
  120.     /* now display them six by six with a small delay */
  121.     lc.setRow(0, 0, six[0]);
  122.     lc.setRow(0, 1, six[1]);
  123.     lc.setRow(0, 2, six[2]);
  124.     lc.setRow(0, 3, six[3]);
  125.     lc.setRow(0, 4, six[4]);
  126.     lc.setRow(0, 5, six[5]);
  127.     lc.setRow(0, 6, six[6]);
  128.     lc.setRow(0, 7, six[7]);
  129.  
  130.     delay(delaytime);
  131. }
  132.  
  133.  
  134. void loop() {
  135.     int x;
  136.     if (digitalRead(BUTTON1))
  137.     {
  138.         x = random(1, 6);
  139.     }
  140.     switch (x) {
  141.     case 1: one1();
  142.         break;
  143.     case 2: two2();
  144.         break;
  145.     case 3: three3();
  146.         break;
  147.     case 4: four4();
  148.         break;
  149.     case 5: five5();
  150.         break;
  151.     case 6: six6();
  152.         break;
  153.     }
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement