Cut cord in length

See:

Add to the code a variable that is incremented when the switch closes.