Is it possible to code a DPDT switch?

PaulRB:
(connected to the 5V pin not the Vin pin)

so i should connect the battery to the 5v pin right?