TIP: Click on subject to list as thread! ANSI
echo: rberrypi
to: ALL
from: DENNIS LEE BIEBER
date: 2018-02-20 00:22:00
subject: Re: How to use while loop

On Mon, 19 Feb 2018 19:08:31 -0800 (PST), ewholz@gmail.com declaimed the
following:


>I leave the program running, and detect when door opens, and when door
>closes - but desire just one line of "OPEN" or "CLOSE"
>

 Without providing any actual code...

 You need to keep a "history" state... AND you need to use an IF/ELSE-IF
structure.

 newState = readPin()
 if lastState == closed and newState == opened:
  print opened
 elif lastState == opened and newState == closed:
  print closed
 lastState = newState

 Using two IF blocks, without an ELSE block means the second IF gets
tested even after you execute the contents of the first IF -- and the first
IF (in your code) has set the history such that the other IF triggers and
outputs...

--
 Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

--- SoupGate-Win32 v1.05
* Origin: Agency HUB, Dunedin - New Zealand | FidoUsenet Gateway (3:770/3)

SOURCE: echomail via QWK@docsplace.org

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.