On 02/19/2018 09:08 PM, ewholz@gmail.com wrote:
> 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
>
Here is how to do it using Tcl instead of Python (based on what I did
you should be able to translate it to Python("
package require piio
##
## The program is run as: tclsh door.tcl
## where is replaced by the real PIIO pin number
##
set inputPin [lindex $argv 0]
piio function $inputPin input
piio pull down $inputPin
piio event $inputPin rising [list puts stdout Open]
piio event $inputPin falling [list puts stdout Close]
vwait forever
--
+----------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald.Lester@kng-consulting.net |
+----------------------------------------------------------------------+
--- SoupGate-Win32 v1.05
* Origin: Agency HUB, Dunedin - New Zealand | FidoUsenet Gateway (3:770/3)
|