Advertisement
Guest User

Untitled

a guest
Dec 27th, 2019
581
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.66 KB | None | 0 0
  1. void (*spustProgram[])(int) = {
  2.   bila,
  3.   cervena,
  4.   modra,
  5.   zelena,
  6.   zluta
  7. };
  8.  
  9. int poleProgramu[22][3] = {
  10.     { 4, 4, 4 },
  11.     { 4, 3, 1 },
  12.     { 2, 3, 4 },
  13.     { 3, 2, 3 },
  14.     { 2, 1, 4 },
  15.     { 1, 1, 4 },
  16.     { 2, 2, 2 },
  17.     { 3, 3, 3 },
  18.     { 1, 1, 1 },
  19.     { 2, 2, 1 },
  20.     { 2, 2, 3 },
  21.     { 2, 3, 2 },
  22.     { 3, 1, 4 },
  23.     { 1, 4, 3 },
  24.     { 3, 1, 2 },
  25.     { 2, 4, 1 },
  26.     { 1, 2, 4 },
  27.     { 2, 1, 3 },
  28.     { 1, 2, 0 },
  29.     { 0, 4, 2 },
  30.     { 2, 3, 0 },
  31.     { 2, 2, 0 }
  32.          
  33.   };
  34. int  programF2(int program, int poc)
  35. {
  36.  
  37.     if (poc < (pocetLED + 1)) {
  38.       // pokud je pocet kroku mensi nez diody budeme vse rozinat
  39.  
  40.       if (poc > -1 and poc < 80) {
  41.  
  42.          (*spustProgram[poleProgramu[program][0]])(poc);
  43.  
  44.       } else if (poc > 79 and poc < 115) {
  45.  
  46.        (*spustProgram[poleProgramu[program][1]])(poc);
  47.  
  48.       } else {
  49.  
  50.         (*spustProgram[poleProgramu[program][2]])(poc);
  51.  
  52.       }
  53.  
  54.     } else if (poc > (pocetLED * 2) and poc < ((pocetLED + 1) * 3)) {
  55.       // pokud je pocet vetsi a zaroven mensi nez 2x pocet pak budeme zhasinat
  56.  
  57.       zhasni(poc - (pocetLED * 2) - 1);
  58.  
  59.     } else if (poc > (pocetLED * 3 + 1)) {
  60.       zmena = 1;
  61.     }
  62.     return zmena;
  63. }
  64.  
  65. void loop() {
  66.  
  67.   Serial.print("Krok: ");
  68.   Serial.print(poc);
  69.   Serial.print(" program: ");
  70.   Serial.print(program);
  71.  
  72.  
  73.   //zmena = programF(program, poc);
  74.    zmena = programF2(program, poc);
  75.   Serial.print(" zmena: ");
  76.   Serial.println(zmena);
  77.  
  78.   if (zmena == 1) {
  79.  
  80.     zmena = 0;
  81.     poc = -1;
  82.  
  83.     if (program > 25) {
  84.       program = 1;
  85.     } else {
  86.       program++;
  87.     }
  88.  
  89.   }
  90.  
  91.   poc++;
  92.   delay(50);
  93.  
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement