const int pins[] = {23, 22, 19, 18, 5, 21, 4}; // 7-segment display pins (A, B, C, D, E, F, G)
const int data[10][7] = {
{0, 0, 0, 0, 0, 0, 1}, // 0
{1, 0, 0, 1, 1, 1, 1}, // 1
{0, 0, 1, 0, 0, 1, 0}, // 2
{0, 0, 0, 0, 1, 1, 0}, // 3
{1, 0, 0, 1, 1, 0, 0}, // 4
{0, 1, 0, 0, 1, 0, 0}, // 5
{0, 1, 0, 0, 0, 0, 0}, // 6
{0, 0, 0, 1, 1, 1, 1}, // 7
{0, 0, 0, 0, 0, 0, 0}, // 8
{0, 0, 0, 0, 1, 0, 0} // 9
};
const int switchPin = 14; // Button pin
int currentValue = 0;
int direction = 1; // 1 for up, -1 for down
int switchState;
int lastSwitchState = HIGH;
void setup() {
Serial.begin(115200);
for (int x = 0; x < 7; x++) {
pinMode(pins[x], OUTPUT);
}
pinMode(switchPin, INPUT_PULLUP);
}
void loop() {
switchState = digitalRead(switchPin);
if (switchState == LOW && lastSwitchState == HIGH) { // Detect button press
currentValue += direction;
// Change direction at boundaries (0 and 9)
if (currentValue == 9) {
direction = -1;
} else if (currentValue == 0) {
direction = 1;
}
Serial.println(currentValue);
delay(150); // Debounce delay
}
// Update the 7-segment display
for (int x = 0; x < 7; x++) {
digitalWrite(pins[x], data[currentValue][x]);
}
lastSwitchState = switchState;
}