Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "SevSeg.h"
- SevSeg sevseg;
- const int buttonPin1 = 14 ;
- int buttonState1 = 0;
- bool bPress1 = false;
- int buttonPushCounter1 = 0; // counter for the number of button
- int lastButtonState1 = 0; // previous state of the button
- const int buttonPin2 = 15 ;
- int buttonState2 = 0;
- bool bPress2 = false;
- int buttonPushCounter2 = 0; // counter for the number of button
- int lastButtonState2 = 0; // previous state of the button
- const int buttonPin3 = 16 ;
- int buttonState3 = 0;
- bool bPress3 = false;
- int buttonPushCounter3 = 0; // counter for the number of button
- int lastButtonState3 = 0; // previous state of the button
- const int buttonPin4 = 17 ;
- int buttonState4 = 0;
- bool bPress4 = false;
- int buttonPushCounter4 = 0; // counter for the number of button
- int lastButtonState4 = 0; // previous state of the button
- int w ;
- int x ;
- int y ;
- int z ;
- void setup() {
- pinMode(buttonPin1, INPUT);
- pinMode(buttonPin2, INPUT);
- pinMode(buttonPin3, INPUT);
- pinMode(buttonPin4, INPUT);
- byte numDigits = 4;
- byte digitPins[] = {2, 3, 4, 5};
- byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12, 13};
- sevseg.begin(COMMON_CATHODE, numDigits, digitPins, segmentPins);
- }
- void yield()
- {
- sevseg.refreshDisplay();
- }
- void loop() {
- buttonState1 = digitalRead(buttonPin1);
- // compare the buttonState to its previous state
- if (buttonState1 != lastButtonState1) {
- // if the state has changed, increment the counter
- if (buttonState1 == LOW) {
- // if the current state is HIGH then the button went from off to on:
- bPress1 = true;
- w = buttonPushCounter1++;
- if( buttonPushCounter1 > 9) buttonPushCounter1 =0 ;
- } else { }
- // Delay a little bit to avoid bouncing
- delay(50);
- }
- // save the current state as the last state, for next time through the loop
- lastButtonState1 = buttonState1;
- buttonState2 = digitalRead(buttonPin2);
- // compare the buttonState to its previous state
- if (buttonState2 != lastButtonState2) {
- // if the state has changed, increment the counter
- if (buttonState2 == LOW) {
- // if the current state is HIGH then the button went from off to on:
- bPress2 = true;
- x = buttonPushCounter2++;
- if( buttonPushCounter2 > 9) buttonPushCounter2 =0 ;
- } else { }
- }
- // save the current state as the last state, for next time through the loop
- lastButtonState2 = buttonState2;
- buttonState3 = digitalRead(buttonPin3);
- // compare the buttonState to its previous state
- if (buttonState3 != lastButtonState3) {
- // if the state has changed, increment the counter
- if (buttonState3 == LOW) {
- // if the current state is HIGH then the button went from off to on:
- bPress3 = true;
- y = buttonPushCounter3++;
- if( buttonPushCounter3 > 9) buttonPushCounter3 =0 ;
- } else { }
- }
- // save the current state as the last state, for next time through the loop
- lastButtonState3 = buttonState3;
- buttonState4 = digitalRead(buttonPin4);
- // compare the buttonState to its previous state
- if (buttonState4 != lastButtonState4) {
- // if the state has changed, increment the counter
- if (buttonState4 == LOW) {
- // if the current state is HIGH then the button went from off to on:
- bPress4 = true;
- z = buttonPushCounter4++;
- if( buttonPushCounter4 > 9) buttonPushCounter4 =0 ;
- } else { }
- }
- // save the current state as the last state, for next time through the loop
- lastButtonState4 = buttonState4;
- sevseg.setNumber(w|x|y|z,3);
- sevseg.setBrightness(100);
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement