Explorer Pro HAT primitive intruder detector code

A little explanation:

explorerhat.touch.pressed is a nifty function which assigns an “event handler” and always runs it when it a button is pressed. You can tell it what to do right at the beginning of your code, and then forget about it. There’s no need to rebind those functions.

Also, channel is already a variable containing the number which I think corresponds to the numbers you want to enter into your system- 1,2,3,4. By using channel as the number we append onto the PIN_INPUT list, we don’t have to use a separate event handler function for each button- we can recycle the same one!

def handle_press(channel, event):
    '''
    Add the number that's been pressed to
    INPUT_PIN every time a butotn is pressed
    '''
    print('Got {event} on {channel}'.format(event=event, channel=channel))
    if channel <= 4:
        INPUT_PIN.append(channel)

Once set up, you can use the same handler to capture the PIN and the DISARM value just by watching a new value, INPUT_PIN and waiting for it to fill up.