Hello Group,
I found a nice program for detecting if a door is open or closed. The example I am using works, but it continually loops if the door is open, writing "Door Open" to my log file. It writes just one event of "Door Closed" (which is what I want).
I would like the program to be running all the time, and if the door is opened write "Door Opened at [time, etc]" one time.
And when the door is closed - write "Door Closed at [time, etc]"
Here is the code I am currently using: while True:
## if the switch is open if io.input(door_pin): io.output(pin,1)## Switch on pin 25 foo.door_event(door_pin) ## foo writes to a file ## logger.log("Door","Open") # stream a message saying "Open" ## logger.flush() # send the message immediately door=0 # set door to its initial value of zero time.sleep(1) # wait 1 second before the next action ## if the switch is closed and door does not equal 1 if (io.input(door_pin)==False and door!=1): io.output(pin,0) ## Switch off pin 25 time.sleep(speed / 2) ## Wait foo.door_event(0) ## logger.log("Door","Close") # stream a message saying "Close" ## logger.flush() # send the message immediately door = 1 # set door so that this loop won't act again until the switch # has been opened
I leave the program running, and detect when door opens, and when door closes - but desire just one line of "OPEN" or "CLOSE"
any tips will help,
thanks
ewholz