#!/usr/bin/env python3

import time
from time import sleep
import RPi.GPIO as GPIO

pin_back = 19
pin_front = 21

GPIO.setmode(GPIO.BOARD)
GPIO.setup(pin_back, GPIO.IN)  # , pull_up_down=GPIO.PUD_DOWN)
previous_state = None


def my_callback(channel):
    global previous_state
    # time.sleep(0.2)  # confirm the movement by waiting 1.5 sec
    pin_val = GPIO.input(pin_back)

    if pin_val != previous_state:
        previous_state = pin_val

        if pin_val:  # and check again the input
            print("[ ] DOOR CLOSED !")
        else:
            print("[+] DOOR OPENED !")


GPIO.add_event_detect(pin_back, GPIO.BOTH, callback=my_callback)
# , bouncetime=500)

# you can continue doing other stuff here
while True:
    time.sleep(50000)
    pass
