Single pin as input and output
The source code for the 1-Wire protocol is a great place to start when learning how to use a single pin for both input and output. 

See also chap. 18. I/O-Ports in the ATmega328p datasheet. 

Cheers!