code refactored to use rpi.gpio event interrupts