Switch code added

Only counts time when switch is ON state.