const int BUTTON_PIN = PA0;
const int SEGMENT_PINS[] = {PA7, PA6, PB4, PB5, PB6, PA8, PA9};
const byte DIGIT_MAP[][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, 0, 0}, // 7
{1, 1, 1, 1, 1, 1, 1}, // 8
{1, 1, 1, 1, 0, 1, 1} // 9
};
int count = 0;
int buttonState;
int lastButtonState = HIGH;
unsigned long lastDebounceTime = 0;
const unsigned long debounceDelay = 50;
void displayDigit(int digit) {
for (int i = 0; i < 7; i++) {
digitalWrite(SEGMENT_PINS[i], DIGIT_MAP[digit][i]);
}
}
void setup() {
for (int i = 0; i < 7; i++) {
pinMode(SEGMENT_PINS[i], OUTPUT);
digitalWrite(SEGMENT_PINS[i], LOW);
}
pinMode(BUTTON_PIN, INPUT_PULLUP);
displayDigit(count);
}
void loop() {
int reading = digitalRead(BUTTON_PIN);
if (reading != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != buttonState) {
buttonState = reading;
if (buttonState == LOW) {
count = (count + 1) % 10;
displayDigit(count);
}
}
}
lastButtonState = reading;
}