#define btnA 13
#define btnB 12
#define btnC 14
int del=50, n=0, chr=99;
const int segmentPinsNum[] = {19,21,17,5,18,22,23};
const int digitPins[] = {16,4,0};
const byte chrs[3][7] = { // 0-9
{1, 1, 1, 0, 1, 1, 1}, // A
{0, 0, 1, 1, 1, 1, 1}, // b
{0, 0, 0, 1, 1, 0, 1} // c
};
const byte digits[10][7] = { // 0-9
{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, 0, 0}, // 7
{1, 1, 1, 1, 1, 1, 1}, // 8
{1, 1, 1, 1, 0, 1, 1} // 9
};
void setup() {
pinMode(btnA, INPUT);
pinMode(btnB, INPUT);
pinMode(btnC, INPUT);
for (int i = 0; i < 7; i++) {
pinMode(segmentPinsNum[i], OUTPUT);
}
for (int i = 0; i < 3; i++) {
pinMode(digitPins[i], OUTPUT);
}
}
void loop() {
if(digitalRead(btnA)){
while(digitalRead(btnA)){}
chr=0;n++;
}
if(digitalRead(btnB)){
while(digitalRead(btnB)){}
chr=1;n++;
}
if(digitalRead(btnC)){
while(digitalRead(btnC)){}
chr=2;n++;
}
if(n>99){n=0;}
while (!(digitalRead(btnA) || digitalRead(btnB)|| digitalRead(btnC))) {
displayNumber(n);
}
}
void displayNumber(int number) {
int tens = number / 10;
int ones = number % 10;
// Display tens digit
displayDigit(tens);
digitalWrite(digitPins[0], LOW);
delay(del);
digitalWrite(digitPins[0], HIGH);
// Display ones digit
displayDigit(ones);
digitalWrite(digitPins[1], LOW);
delay(del);
digitalWrite(digitPins[1], HIGH);
// Display letter digit
displayChr(chr);
digitalWrite(digitPins[2], LOW);
delay(del);
digitalWrite(digitPins[2], HIGH);}
void displayDigit(int digit) {
for (int i = 0; i < 7; i++) {
digitalWrite(segmentPinsNum[i], digits[digit][i]);
}
}
void displayChr(int digit) {
for (int i = 0; i < 7; i++) {
digitalWrite(segmentPinsNum[i], chrs[digit][i]);
}
}