The code is working as intended functionality wise, and the problem is the 'A' part of the seven segment, or the top LED line is not lighting up from digits 0 to 9, with the exception of 7. I do not know why is this happening, maybe using byte mode somehow messing up the D0 pin? Maybe perhaps the way I store counts on each button press? I appreciate any help since I am a beginner.
This is what I am trying to accomplish:
Here is my code:
#define PORTD_CONFIG (0xFF)
#define SEG_0 (0x40) // 01000000 - All segments except g (a, b, c, d, e, f)
#define SEG_1 (0x79) // 01111001 - Only segments b and c
#define SEG_2 (0x24) // 00100100 - Segments a, b, d, e, g
#define SEG_3 (0x30) // 00110000 - Segments a, b, c, d, g
#define SEG_4 (0x19) // 00011001 - Segments b, c, f, g
#define SEG_5 (0x12) // 00010010 - Segments a, c, d, f, g
#define SEG_6 (0x02) // 00000010 - Segments a, c, d, e, f, g
#define SEG_7 (0x78) // 01111000 - Only segments a, b, c
#define SEG_8 (0x00) // 00000000 - All segments a-g
#define SEG_9 (0x10) // 00010000 - Segments a, b, c, d, f, g
#define STOP_DISP (0xFF)
#define BUTTON1 (8)
#define SEG_DEL delay(500)
int count = 0;
void setup() {
DDRD = PORTD_CONFIG;
pinMode(BUTTON1, INPUT);
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
PORTD = STOP_DISP;
}
void loop() {
unsigned int seg_disp[] = {SEG_0, SEG_1, SEG_2, SEG_3, SEG_4, SEG_5, SEG_6, SEG_7, SEG_8, SEG_9};
bool buttonState = LOW;
bool lastButtonState = LOW;
// Read button state with debouncing
buttonState = digitalRead(BUTTON1);
if (buttonState != lastButtonState) {
SEG_DEL;
buttonState = digitalRead(BUTTON1);
}
// Check for button press (LOW to HIGH transition)
if (buttonState == HIGH && lastButtonState == LOW) {
count++;
if (count >= 4) count = 0;
}
// Update the last button state
lastButtonState = buttonState;
switch (count) {
case 0:
for (int i = 0; i < 10; i++) {
PORTD = seg_disp[i];
SEG_DEL;
}
break;
case 1:
for (int i = 1; i <= 9; i += 2) {
PORTD = seg_disp[i];
SEG_DEL;
}
break;
case 2:
for (int i = 9; i >= 0; i--) {
PORTD = seg_disp[i];
SEG_DEL;
}
break;
case 3:
for (int i = 0; i <= 8; i += 2) {
PORTD = seg_disp[i];
SEG_DEL;
}
break;
default:
count = 0;
break;
}
}
Here are images:


