#include <SegmentDisplay_CD4511B.h>
#include <Pushbutton.h>
int x,y,z;
int digit[10][7] = {
{1,1,1,1,1,1,0}, //0
{0,1,1,0,0,0,0}, //1
{1,1,0,1,1,0,1}, //2
{1,1,1,1,0,0,1}, //3
{0,1,1,0,0,1,1}, //4
{1,0,1,1,0,1,1}, //5
{1,0,1,1,1,1,1}, //6
{1,1,1,0,0,1,0}, //7
{1,1,1,1,1,1,1}, //8
{1,1,1,1,0,1,1} //9
};
const int buttonPin = 9; //push button attached to this pin
const int buttonPin2 = 10;
int buttonState = LOW; //this variable tracks the state of the button, low if not pressed, high if pressed
int buttonState2 = LOW;
int lastButtonState = LOW;
int currentCount = 0;
int maxCount = 9;
int minCount = 0;
// int ledState = -1; //this variable tracks the state of the LED, negative if off, positive if on
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 50;
void setup() {
//Setting pin 2-8 as OUTPUT
for(x=2;x<=8;x++){
pinMode(x,OUTPUT);
}
pinMode(buttonPin, INPUT);
pinMode(buttonPin2, INPUT);
Serial.begin(9600);
}
void loop() {
// buttonState = digitalRead(PushButton1);
//sample the state of the button - is it pressed or not?
buttonState = digitalRead(buttonPin);
buttonState2 = digitalRead(buttonPin2);
// Loop y will continue for count 0 to 9
if(buttonState != lastButtonState) {
if ( (buttonState == HIGH) && (buttonState2 == LOW) ) {
currentCount = max(minCount, currentCount);
Serial.print(buttonState);
// lastButtonState = buttonState;
for(y=currentCount; y<=9; y++){
// Loop z will continue for 7 segment display high or low
for(z=0; z<=6; z++){
digitalWrite(z+2,digit[y][z]);
}
delay(1000);
buttonState = digitalRead(buttonPin);
Serial.print("second");
Serial.print(buttonState);
if(buttonState != lastButtonState && (buttonState == LOW || buttonState2 == HIGH)) {
if(y == maxCount) {
currentCount = 0;
}
else{
currentCount = y;
}
Serial.print(currentCount);
break;
}
lastButtonState = buttonState;
}
lastDebounceTime = millis();
}
}
lastButtonState = buttonState;
if(buttonState2 != lastButtonState) {
if ( (buttonState == LOW) && (buttonState2 == HIGH) ) {
for(y=9; y>=0; y--){
// Loop z will continue for 7 segment display high or low
for(z=6; z>=0; z--){
digitalWrite(z+2,digit[y][z]);
}
delay(1000);
}
lastDebounceTime = millis();
}
}
}