Advertisement
Muzaffar79

Untitled

Apr 29th, 2018
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int led = 13;
  2. int led1 = 12;
  3. int led2 = 11;
  4. int led3 = 10;
  5. int led4 = 9;
  6. int led5 = 8;
  7. int led6 = 7;
  8.  
  9. int switchUpPin = 2;
  10. int switchDownPin = 3;
  11.  
  12. int counter = 0;
  13. int counter1 = 0;
  14.  
  15. int buttonUpState = 0;
  16. int lastButtonUpState = 0;
  17.  
  18. int buttonDownState = 0;
  19. int lastButtonDownState = 0;
  20.  
  21. int buttonUpState1 = 0;
  22. int lastButtonUpState1 = 0;
  23.  
  24. int buttonUpState2 = 0;
  25. int lastButtonUpState2 = 0;
  26.  
  27.  
  28.  
  29. void setup()
  30. {
  31.   Serial.begin(9600);
  32.  
  33.    pinMode(led, OUTPUT);  
  34.  pinMode(led1, OUTPUT);
  35.  pinMode(led2, OUTPUT);
  36.  pinMode(led3, OUTPUT);
  37.  pinMode(led4, OUTPUT);
  38.  pinMode(led5, OUTPUT);
  39.  pinMode(led6, OUTPUT);
  40.  
  41. }
  42.  
  43. void loop()
  44. {
  45.   buttonUpState = digitalRead(switchUpPin);
  46.   buttonDownState = digitalRead(switchDownPin);
  47.  
  48.  
  49.   if (buttonUpState != lastButtonUpState)
  50.   {
  51.     if (buttonUpState == HIGH)
  52.     {
  53.       if(counter == 9)
  54.       {
  55.         counter = -1;
  56.       }
  57.       counter++;
  58.      
  59.       Serial.println(counter);
  60.       changeNumber(counter);
  61.       delay(300);
  62.     }
  63.     else
  64.     {
  65.         Serial.println("OFF");
  66.     }
  67.    delay(50);
  68.   }
  69.  
  70.  
  71. if (buttonDownState != lastButtonDownState)
  72.   {
  73.     if (buttonDownState == HIGH)
  74.     {
  75.       if(counter == 0)
  76.       {
  77.         counter = 10;
  78.       }
  79.       counter--;
  80.       Serial.println(counter);
  81.       changeNumber(counter);
  82.       delay(300);
  83.     }
  84.     else
  85.     {
  86.         Serial.println("OFF");
  87.     }
  88.    delay(50);
  89.   }
  90.   changeNumber(counter);
  91. }
  92.  
  93.  
  94.  
  95.  
  96.  
  97. void changeNumber(int buttonPress)
  98. {
  99.   switch (buttonPress)
  100.   {
  101.     //number 0
  102.     case 0:
  103.      digitalWrite(led, HIGH);
  104.  digitalWrite(led1, HIGH);
  105.   digitalWrite(led2, LOW);
  106.  digitalWrite(led3, HIGH);
  107.  digitalWrite(led4, HIGH);
  108.  digitalWrite(led5, HIGH);
  109.  digitalWrite(led6, HIGH);
  110.       break;
  111.     //number 1
  112.     case 1:
  113.       digitalWrite(led, HIGH);
  114.  digitalWrite(led1, HIGH);
  115.  digitalWrite(led2, LOW);
  116.  digitalWrite(led3, LOW);
  117.  digitalWrite(led4, LOW);
  118.  digitalWrite(led5, LOW);
  119.  digitalWrite(led6, LOW);
  120.       break;
  121.     //number 2
  122.     case 2:
  123.       digitalWrite(led, HIGH);
  124.  digitalWrite(led1, LOW);
  125.  digitalWrite(led2, HIGH);
  126.  digitalWrite(led3, HIGH);
  127.  digitalWrite(led4, LOW);
  128.  digitalWrite(led5, HIGH);
  129.  digitalWrite(led6, HIGH);  
  130.       break;
  131.     //number 3
  132.     case 3:
  133.       digitalWrite(led, HIGH);
  134.  digitalWrite(led1, HIGH);
  135.  digitalWrite(led2, HIGH);
  136.  digitalWrite(led3, HIGH);
  137.  digitalWrite(led4, LOW);
  138.  digitalWrite(led5, HIGH);
  139.  digitalWrite(led6, LOW);
  140.       break;
  141.     //number 4
  142.     case 4:
  143.       digitalWrite(led, HIGH);
  144.  digitalWrite(led1, HIGH);
  145.  digitalWrite(led2, HIGH);
  146.  digitalWrite(led3, LOW);
  147.  digitalWrite(led4, HIGH);
  148.  digitalWrite(led5,LOW);
  149.  digitalWrite(led6, LOW);
  150.       break;
  151.     //number 5
  152.     case 5:
  153.      digitalWrite(led, LOW);
  154.  digitalWrite(led1, HIGH);
  155.  digitalWrite(led2, HIGH);
  156.  digitalWrite(led3, HIGH);
  157.  digitalWrite(led4, HIGH);
  158.  digitalWrite(led5, HIGH);
  159.  digitalWrite(led6, LOW);
  160.       break;
  161.     //number 6
  162.     case 6:
  163.      digitalWrite(led, LOW);
  164.  digitalWrite(led1, HIGH);
  165.  digitalWrite(led2, HIGH);
  166.  digitalWrite(led3, HIGH);
  167.  digitalWrite(led4, HIGH);
  168.  digitalWrite(led5,HIGH);
  169.  digitalWrite(led6, HIGH);
  170.       break;
  171.     //number 7
  172.     case 7:
  173.      digitalWrite(led, HIGH);
  174.  digitalWrite(led1, HIGH);
  175.  digitalWrite(led2, LOW);
  176.  digitalWrite(led3, HIGH);
  177.  digitalWrite(led4, LOW);
  178.  digitalWrite(led5,LOW);
  179.  digitalWrite(led6, LOW);
  180.       break;
  181.     //number 8
  182.     case 8:
  183.       digitalWrite(led, HIGH);
  184.  digitalWrite(led1, HIGH);
  185.  digitalWrite(led2, HIGH);
  186.  digitalWrite(led3, HIGH);
  187.  digitalWrite(led4, HIGH);
  188.  digitalWrite(led5,HIGH);
  189.  digitalWrite(led6, HIGH);
  190.       break;
  191.     //number 9
  192.     case 9:
  193.      digitalWrite(led, HIGH);
  194.  digitalWrite(led1, HIGH);
  195.  digitalWrite(led2, HIGH);
  196.  digitalWrite(led3, HIGH);
  197.  digitalWrite(led4, HIGH);
  198.  digitalWrite(led5,HIGH);
  199.  digitalWrite(led6, LOW);
  200.       break;
  201.   }
  202.  
  203.  
  204. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement