Code based on debounce from examples (license needs returning as I removed it accidentally, I'll do this at next checkin)
Code still fairly dirty but working it seems.