Help using Port Manipulation using Arduino Uno

Hi, I am having trouble with my code. The goal of this code is to get two sets of LEDs to blink a 0-15 counting sequence in binary when their assigned push button is pressed. There are two buttons and button 1 has priority over button 2 meaning that if button 1 is pressed while button 2’s LEDs are counting then button 2’s LEDs will pause and let button 1’s LEDs count 0 - 15 before letting button 2 finish its cycle.

The problem I am having assigning the buttons and LED pins properly. I need button 1 assigned as an input to pin 12 and button 2 assigned as an input to pin 13 but the buttons do not function when I run the program. For the LEDS, I have successfully assigned the button 1 LED’s using DDRD = B00111100; but, group 2 LEDs do not work at all even though I set it up like DDRB = B00001111;. Is there anyway to correct this code? (The hardware does work as I have a working code using the digitalWrite and pinMode functions. I wanted to minimize the use of storage space by using port manipulation.

[byte DisplayBinary = {B00000000, // Binary representation of 0
B00000100, // Binary representation of 1
B00001000, // Binary representation of 2
B00001100, // Binary representation of 3
B00010000, // Binary representation of 4
B00010100, // Binary representation of 5
B00011000, // Binary representation of 6
B00011100, // Binary representation of 7
B00100000, // Binary representation of 8
B00100100, // Binary representation of 9
B00101000, // Binary representation of 10
B00101100, // Binary representation of 11
B00110000, // Binary representation of 12
B00110100, // Binary representation of 13
B00111000, // Binary representation of 14
B00111100, // Binary representation of 15
B00000000}; // Binary representation of 0 & turns off all LEDs

void setup()
{
DDRD = B00111100; // Represents group 1 pins 2,3,4,5 and sets as outputs
DDRB = B00001111; // Represents group 2 pins 8,9,10,11 and sets an outputs
}

void loop()
{
if (PINB & (1<<12)) // sets pin 12 as button 1 input
{
group1 (); // Calls this function if button 1 is pressed
}
if (PINB & (1<<13)) // sets pin 13 as button 2 input
{
group2 (); // calls functions if button 2 is pressed
}
} //end of loop

// Call function for instructions when button 1 is pressed
void group1 ()
{
for (int up = 0; up<17; up++) // Loop 17 times for each binary value in DisplayBinary
{
PORTD = DisplayBinary[up]; // Sends HIGH or LOW outputs to the LEDS for group 1 (pins 2,3,4,5)
delay (500); // Delays the next function for 500 ms or 0.5 seconds
}
}// end of loop

// Call function for instructions when button 2 is pressed
void group2 ()
{
for (int up = 0; up<17; up++) // Loop 17 times for each binary value in Byte2DisplayBinary
{
if (PINB & (1<<12)) // If Pushbutton 1 is pressed for group 1 (Group 1 is listed because
// group 1 has priority over group 2)
{
group1 (); // Call function to execute instructions if Pushbutton 1 was press
}
PORTB = DisplayBinary[up]; // Send HIGH/LOW outputs to the LEDs for group 2 (Pins 8,9,10,11)
delay(500); // Delays the next function for 500 ms or 0.5 seconds
} // end of for loop
} //end of loop
]

What do you think these do?
PINB & (1<<12)
PINB & (1<<13)

How many bits are involved when you do a PINB?

if (PINB & (1<<12))      // sets pin 12 as button 1 input

Pin 12 is in PORTB, try:

if (PINB & (1 <<12 - 8))      // sets pin 12 as button 1 input

That will READ pin 12. (PORTB,4)

outsider:
That will READ pin 12.

On my Uno each PORT has 8 pins, Where did you find the 12th one?

There is no simple relationship between Arduino pin numbers and the pins in PORTs. Have a look at the Atmega 328 pin mapping diagram.

...R