code refactoring to use rpi.gpio event interrupts