Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.08 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int l[5];
  5.  
  6.  
  7. bool s1, s2, s3, s4, s5;
  8.  
  9.  
  10. void Pisz()
  11. {
  12.     for (int i = 0; i < 5; i++)
  13.     {
  14.         cout << "l" << i+1 << " = "<<l[i]<<" ";
  15.     }
  16.     cout <<endl<< "s1 = " << s1 << " s2 = " << s2 << " s3 = " << s3 << " s4 = " << s4 << " s5 = " << s5 << endl;
  17. }
  18.  
  19. void Ustaw()
  20. {
  21.  
  22.     if (l[0] > 0)
  23.         s1 = true;
  24.     else
  25.     {
  26.         s1 = false;
  27.     }
  28.     if (l[1] > 0)
  29.         s2 = true;
  30.     else
  31.     {
  32.         s2 = false;
  33.     }
  34.     if (l[2] > 0)
  35.         s3 = true;
  36.     else
  37.     {
  38.         s3 = false;
  39.     }
  40.     if (l[3] > 0)
  41.         s4 = true;
  42.     else
  43.     {
  44.         s4 = false;
  45.     }
  46.     if (l[4] > 0)
  47.         s5 = true;
  48.     else
  49.     {
  50.         s5 = false;
  51.     }
  52.  
  53.     /*
  54.     if (l[0] > 0)
  55.         IOWR(LEDS_BASE, 0 , LEDS1 | IORD(LEDS_BASE,0))
  56.     else
  57.     {
  58.     s1 = false;
  59.     }
  60.     if (l[1] > 0)
  61.         IOWR(LEDS_BASE, 0 , LEDS2)
  62.     else
  63.     {
  64.     s2 = false;
  65.     }
  66.     if (l[2] > 0)
  67.         IOWR(LEDS_BASE, 0 , LEDS3)
  68.     else
  69.     {
  70.     s3 = false;
  71.     }
  72.     if (l[3] > 0)
  73.         IOWR(LEDS_BASE, 0 , LEDS4)
  74.     else
  75.     {
  76.     s4 = false;
  77.     }
  78.     if (l[4] > 0)
  79.         IOWR(LEDS_BASE, 0 , LEDS5)
  80.     else
  81.     {
  82.     s5 = false;
  83.     }
  84.  
  85.  
  86.     */
  87. }
  88.  
  89. int kier, s;
  90.  
  91. int main()
  92. {
  93.     kier = 1;
  94.     s = 0;
  95.     for (int i = 0; i < 5; i++)
  96.     {
  97.         l[i] = 1;
  98.     }
  99.     while (1)
  100.     {
  101.         Ustaw();
  102.         Pisz();
  103.         cout << endl << "podaj s ";
  104.  
  105.         cin >> s >> kier;
  106.  
  107.  
  108. /*
  109.         kier = IORD(SW_SLIDERS_BASE, 0) & SW9;
  110.         s = IORD(SW_SLIDERS_BASE, 0);
  111.  
  112.         if (s & SW1)
  113.         {
  114.             if (kier)
  115.             {
  116.                 if (l[2] > 0)
  117.                 {
  118.                     l[0]++;
  119.                     l[2]--;
  120.                 }
  121.                 else
  122.                     cout << "Brak w pokoju 3\n"; // dioda bledu
  123.             }
  124.             else
  125.             {
  126.                 if (l[0] > 0)
  127.                 {
  128.                     l[0]--;
  129.                     l[2]++;
  130.                 }
  131.                 else
  132.                     cout << "Brak w pokoju 1\n"; // dioda bledu
  133.             }
  134.         }
  135.         else if (s & SW2)
  136.         {
  137.             if (kier)
  138.             {
  139.                 if (l[0] > 0)
  140.                 {
  141.                     l[1]++;
  142.                     l[0]--;
  143.                 }
  144.                 else
  145.                     cout << "Brak w pokoju 1\n"; // dioda bledu
  146.             }
  147.             else
  148.             {
  149.                 if (l[1] > 0)
  150.                 {
  151.                     l[1]--;
  152.                     l[0]++;
  153.                 }
  154.                 else
  155.                     cout << "Brak w pokoju 2\n"; // dioda bledu
  156.             }
  157.         }
  158.         else if (s & SW3)
  159.         {
  160.             if (kier)
  161.             {
  162.                 if (l[1] > 0)
  163.                 {
  164.                     l[4]++;
  165.                     l[1]--;
  166.                 }
  167.                 else
  168.                     cout << "Brak w pokoju 2\n"; // dioda bledu
  169.             }
  170.             else
  171.             {
  172.                 if (l[4] > 0)
  173.                 {
  174.                     l[4]--;
  175.                     l[1]++;
  176.                 }
  177.                 else
  178.                     cout << "Brak w pokoju 5\n"; // dioda bledu
  179.             }
  180.         }
  181.         else if (s & SW4)
  182.         {
  183.             if (kier)
  184.             {
  185.                 if (l[4] > 0)
  186.                 {
  187.                     l[4]--;
  188.                 }
  189.                 else
  190.                     cout << "Brak w pokoju 5\n"; // dioda bledu
  191.             }
  192.             else
  193.             {
  194.                 l[4]++;
  195.             }
  196.         }
  197.         else if (s & SW5)
  198.         {
  199.             if (kier)
  200.             {
  201.                 if (l[2] > 0)
  202.                 {
  203.                     l[3]++;
  204.                     l[2]--;
  205.                 }
  206.                 else
  207.                     cout << "Brak w pokoju 2\n"; // dioda bledu
  208.             }
  209.             else
  210.             {
  211.                 if (l[3] > 0)
  212.                 {
  213.                     l[3]--;
  214.                     l[2]++;
  215.                 }
  216.                 else
  217.                     cout << "Brak w pokoju 5\n"; // dioda bledu
  218.             }
  219.         }
  220.  
  221.         */
  222.  
  223.  
  224.  
  225.         switch (s)
  226.         {
  227.         case 1:
  228.             if (kier)
  229.             {
  230.                 if (l[2] > 0)
  231.                 {
  232.                     l[0]++;
  233.                     l[2]--;
  234.                 }
  235.                 else
  236.                     cout << "Brak w pokoju 3\n";
  237.             }
  238.             else
  239.             {
  240.                 if (l[0] > 0)
  241.                 {
  242.                     l[0]--;
  243.                     l[2]++;
  244.                 }
  245.                 else
  246.                     cout << "Brak w pokoju 1\n";
  247.             }
  248.             break;
  249.         case 2:
  250.             if (kier)
  251.             {
  252.                 if (l[0] > 0)
  253.                 {
  254.                     l[1]++;
  255.                     l[0]--;
  256.                 }
  257.                 else
  258.                     cout << "Brak w pokoju 1\n";
  259.             }
  260.             else
  261.             {
  262.                 if (l[1] > 0)
  263.                 {
  264.                     l[1]--;
  265.                     l[0]++;
  266.                 }
  267.                 else
  268.                     cout << "Brak w pokoju 2\n";
  269.             }
  270.             break;
  271.         case 3:
  272.             if (kier)
  273.             {
  274.                 if (l[1] > 0)
  275.                 {
  276.                     l[4]++;
  277.                     l[1]--;
  278.                 }
  279.                 else
  280.                     cout << "Brak w pokoju 2\n";
  281.             }
  282.             else
  283.             {
  284.                 if (l[4] > 0)
  285.                 {
  286.                     l[4]--;
  287.                     l[1]++;
  288.                 }
  289.                 else
  290.                     cout << "Brak w pokoju 5\n";
  291.             }
  292.             break;
  293.         case 4:
  294.             if (kier)
  295.             {
  296.                 if (l[4] > 0)
  297.                 {
  298.                     l[4]--;
  299.                 }
  300.                 else
  301.                     cout << "Brak w pokoju 5\n";
  302.             }
  303.             else
  304.             {
  305.                 l[4]++;
  306.             }
  307.             break;
  308.         case 5:
  309.             if (kier)
  310.             {
  311.                 if (l[2] > 0)
  312.                 {
  313.                     l[3]++;
  314.                     l[2]--;
  315.                 }
  316.                 else
  317.                     cout << "Brak w pokoju 2\n";
  318.             }
  319.             else
  320.             {
  321.                 if (l[3] > 0)
  322.                 {
  323.                     l[3]--;
  324.                     l[2]++;
  325.                 }
  326.                 else
  327.                     cout << "Brak w pokoju 5\n";
  328.             }
  329.             break;
  330.  
  331.  
  332.         }      
  333.  
  334.     }
  335.  
  336.    
  337.  
  338.     getchar();
  339.    
  340.     return 0;
  341. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement