SHARE
TWEET

Philip

a guest Sep 11th, 2019 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "SevSeg.h"
  2.  
  3. SevSeg sevseg;
  4. const int buttonPin1 = 14 ;    
  5. int buttonState1 = 0;    
  6. bool bPress1 = false;
  7. int buttonPushCounter1 = 0;   // counter for the number of button
  8. int lastButtonState1 = 0;     // previous state of the button
  9.      
  10. const int buttonPin2 = 15 ;    
  11. int buttonState2 = 0;    
  12. bool bPress2 = false;
  13. int buttonPushCounter2 = 0;   // counter for the number of button
  14. int lastButtonState2 = 0;     // previous state of the button
  15.  
  16. const int buttonPin3 = 16 ;    
  17. int buttonState3 = 0;  
  18. bool bPress3 = false;
  19. int buttonPushCounter3 = 0;   // counter for the number of button
  20. int lastButtonState3 = 0;     // previous state of the button
  21.  
  22. const int buttonPin4 = 17 ;    
  23. int buttonState4 = 0;  
  24. bool bPress4 = false;
  25. int buttonPushCounter4 = 0;   // counter for the number of button
  26. int lastButtonState4 = 0;     // previous state of the button      
  27.  
  28.  
  29.  
  30.  
  31.   int w ;
  32.   int x ;
  33.   int y ;
  34.   int z ;
  35.  
  36. void setup() {
  37.  pinMode(buttonPin1, INPUT);
  38.  pinMode(buttonPin2, INPUT);
  39.  pinMode(buttonPin3, INPUT);
  40.  pinMode(buttonPin4, INPUT);
  41.  
  42.  
  43.   byte numDigits = 4;
  44.   byte digitPins[] = {2, 3, 4, 5};
  45.   byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12, 13};
  46.   sevseg.begin(COMMON_CATHODE, numDigits, digitPins, segmentPins);
  47. }
  48.  
  49. void yield()
  50. {
  51.   sevseg.refreshDisplay();
  52. }
  53.  
  54. void loop() {
  55.  
  56. buttonState1 = digitalRead(buttonPin1);
  57.  // compare the buttonState to its previous state
  58.   if (buttonState1 != lastButtonState1) {
  59.     // if the state has changed, increment the counter
  60.     if (buttonState1 == LOW) {
  61.       // if the current state is HIGH then the button went from off to on:
  62.       bPress1 = true;
  63.      w = buttonPushCounter1++;
  64.       if( buttonPushCounter1 > 9) buttonPushCounter1 =0 ;
  65.      
  66.    
  67.     } else { }
  68.     // Delay a little bit to avoid bouncing
  69.     delay(50);
  70.   }
  71.   // save the current state as the last state, for next time through the loop
  72.   lastButtonState1 = buttonState1;
  73.  
  74.  
  75. buttonState2 = digitalRead(buttonPin2);
  76.  // compare the buttonState to its previous state
  77.   if (buttonState2 != lastButtonState2) {
  78.     // if the state has changed, increment the counter
  79.     if (buttonState2 == LOW) {
  80.       // if the current state is HIGH then the button went from off to on:
  81.       bPress2 = true;
  82.      x = buttonPushCounter2++;
  83.       if( buttonPushCounter2 > 9) buttonPushCounter2 =0 ;
  84.  
  85.    
  86.     } else { }
  87.    
  88.   }
  89.   // save the current state as the last state, for next time through the loop
  90.   lastButtonState2 = buttonState2;
  91.  
  92.  
  93.   buttonState3 = digitalRead(buttonPin3);
  94.  // compare the buttonState to its previous state
  95.   if (buttonState3 != lastButtonState3) {
  96.     // if the state has changed, increment the counter
  97.     if (buttonState3 == LOW) {
  98.       // if the current state is HIGH then the button went from off to on:
  99.       bPress3 = true;
  100.      y = buttonPushCounter3++;
  101.       if( buttonPushCounter3 > 9) buttonPushCounter3 =0 ;
  102.  
  103.    
  104.     } else { }
  105.    
  106.   }
  107.   // save the current state as the last state, for next time through the loop
  108.   lastButtonState3 = buttonState3;
  109.  
  110.  
  111. buttonState4 = digitalRead(buttonPin4);
  112.  // compare the buttonState to its previous state
  113.   if (buttonState4 != lastButtonState4) {
  114.     // if the state has changed, increment the counter
  115.     if (buttonState4 == LOW) {
  116.       // if the current state is HIGH then the button went from off to on:
  117.       bPress4 = true;
  118.      z = buttonPushCounter4++;
  119.       if( buttonPushCounter4 > 9) buttonPushCounter4 =0 ;
  120.  
  121.    
  122.     } else { }
  123.    
  124.   }
  125.   // save the current state as the last state, for next time through the loop
  126.   lastButtonState4 = buttonState4;
  127.  
  128.  
  129.  
  130.  
  131.   sevseg.setNumber(w|x|y|z,3);
  132.   sevseg.setBrightness(100);
  133.   delay(1000);
  134.  
  135.   }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top