DDRD is for D7 through D0
76543210
DDRD = 0b10010111;
You would be making D7, D4, D2, D1, D0 outputs
Playing around with D0 and D1 messes with your serial pins.
Then you are switching to port B which is for D13 to D8
1111
321098
DDRB = 0b110001
D13, D12, D8 outputs
The standard way is to use pinMode(pin, mode), where mode is INPUT, INPUT_PULLUP or OUTPUT.
Usually the pin modes are set once early on so it isn't a performance issue and so it's not typically necessary to do direct port writes. You could code it like this:
Thank you Larry. That helps out a lot. I just did a quick LED test to confirm.
Jboyton, I am just curious on port manipulation as this is something I've never learned. Using this along with functions will save me a lot of space in my coding.
On an Uno none of the ports makes all 8 pins available to the user so you should not use = to set values.
For example don't use PORTD = b11110000 because pins 0 and 1 are Rx and Tx
Instead set pins to 1 with PORTD |= b11110000 - using OR the 0s won't change anything
and
set pins to 0 with PORTD &= b00001111 - using AND the 1s won't change anything