I’m trying to understand what the follow sample code does I got from github. Read through the port manipulation docs and still very confused over this.

```
void flash_change_pins_mode(boolean io)
{
if (io) {
DDRD &= ~(1<<2);
DDRD &= ~(1<<3);
DDRD &= ~(1<<4);
DDRD &= ~(1<<5);
DDRD &= ~(1<<6);
DDRD &= ~(1<<7);
DDRB &= ~(1<<0);
DDRB &= ~(1<<1);
}
else
{
DDRD |= (1<<2);
DDRD |= (1<<3);
DDRD |= (1<<4);
DDRD |= (1<<5);
DDRD |= (1<<6);
DDRD |= (1<<7);
DDRB |= (1<<0);
DDRB |= (1<<1);
}
}
```

So if io = 1 then run the first section.

DDRD is port D register. read/write

&= is compound bitwise and

<< shift the bit s left.

So putting all that together what does DDRD |= (1<<2); do?

1<<2 is B00000100. So set pin 2 as output? Then set put 3 as output etc etc. Does this routing just set all the pins as output if io=1 or all inupts if io=0

Isn’t there a less confusing way of doing this?