Read/write digital pin based on variable