#define sw1 2
#define sw2 10
#define sw3 11
int sevSegPin[7] = {5, 6, 7, 9, 4, 3, 8};
int digitSegments[10][7] = {
// 1 2 3 4 5 6 7
{1, 1, 1, 0, 1, 1, 1}, // Digit 0
{1, 0, 0, 0, 1, 0, 0}, // Digit 1
{0, 1, 1, 1, 1, 1, 0}, // Digit 2
{1, 1, 0, 1, 1, 1, 0}, // Digit 3
{1, 0, 0, 1, 1, 0, 1}, // Digit 4
{1, 1, 0, 1, 0, 1, 1}, // Digit 5
{1, 1, 1, 1, 0, 1, 1}, // Digit 6
{1, 0, 0, 0, 1, 1, 0}, // Digit 7
{1, 1, 1, 1, 1, 1, 1}, // Digit 8
{1, 1, 0, 1, 1, 1, 1}, // Digit 9
};
unsigned longlastDebounceTime1, lastDebounceTime1;
int buttonState1 = 0;
int lastButtonState1 = 0;
unsigned countTimer;
int count0 = 0;
int count1 = 0;
void setup() {
Serial.begin(115200);
pinMode(sw1, INPUT);
pinMode(sw2, INPUT);
pinMode(sw3, INPUT);
for (int pixel=0; pixel < 7; pixel++) {
pinMode(sevSegPin[pixel], OUTPUT);
}
countTimer = millis();
}
void printSev(int number) {
for (int pixel=0; pixel < 7; pixel++) {
if (digitSegments[number][pixel] == 0) {
digitalWrite(sevSegPin[pixel], LOW);
} else {
digitalWrite(sevSegPin[pixel], HIGH);
}
}
}
void loop() {
if (digitalRead(sw2) == HIGH){
if ((millis() - countTimer) > 1000) {
printSev(count0);
count0 += 1;
countTimer = millis();
}
if (count0 > 9) {
count0 = 0;
}
}
if (digitalRead(sw3) == HIGH){
if (millis() - lastDebounceTime1 > 50) {
buttonState1 = digitalRead(sw1);
if (buttonState1 != lastButtonState1) {
lastDebounceTime1 = millis();
lastButtonState1 = buttonState1;
if (buttonState1 == HIGH) {
printSev(count1);
count1++;
}
if (count1 > 9) {
count1 = 0;
}
}
}
}
}