Fix off-by-one bugs.
While here, only set the GPIO pin state for output pins.
Pointy hat to: loos Sponsored by: Rubicon Communications (Netgate)