#define btnA 16
#define btnB 2
#define btnC 15
int del=50, n=0;
const int segmentPinsNum[] = {19,21,17,5,18,22,23};
const int digitPins[] = {4, 0};
const int segmentPinsChr[] = {14,12,32,33,25,26,27};
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(segmentPinsChr[i], OUTPUT);
}
for (int i = 0; i < 7; i++) {
pinMode(segmentPinsNum[i], OUTPUT);
}
for (int i = 0; i < 2; i++) {
pinMode(digitPins[i], OUTPUT);
}
}
void loop() {
if(digitalRead(btnA)){
while(digitalRead(btnA)){}
displayChr(0);n++;
}
if(digitalRead(btnB)){
while(digitalRead(btnB)){}
displayChr(1);n++;
}
if(digitalRead(btnC)){
while(digitalRead(btnC)){}
displayChr(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);
}
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(segmentPinsChr[i], chrs[digit][i]);
}
}