Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #69926

Re: "Latching" variables in function

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.027
X-Spam-Evidence '*H*': 0.95; '*S*': 0.00; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.12; 'jan': 0.12; "'port": 0.16; 'handler.': 0.16; 'pressed': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'possible,': 0.19; 'skip:p 40': 0.19; 'header :User-Agent:1': 0.23; "i've": 0.25; 'gets': 0.27; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; "i'm": 0.30; 'code': 0.31; 'probably': 0.32; "can't": 0.35; 'but': 0.35; 'there': 0.35; 'wrong': 0.37; 'project': 0.37; 'button': 0.38; 'depends': 0.38; 'ends': 0.38; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'little': 0.38; 'subject:" ': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'called': 0.40; 'how': 0.40; 'entire': 0.61; 'received:173': 0.61; 'term': 0.63; 'become': 0.64; 'periodically': 0.68; 'plc': 0.78; 'books.': 0.84; 'interrupt': 0.84; 'received:fios.verizon.net': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: "Latching" variables in function
Date Wed, 09 Apr 2014 00:35:01 -0400
References <7ffe44a68f47a64f5120d3a6c6a660b5@myglnc.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-173-75-254-207.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0
In-Reply-To <7ffe44a68f47a64f5120d3a6c6a660b5@myglnc.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.9055.1397018129.18130.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1397018129 news.xs4all.nl 2914 [2001:888:2000:d::a6]:52435
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:69926

Show key headers only | View raw


On 4/8/2014 4:09 PM, Grawburg wrote:
>
> I've probably used the wrong term - I'm thinking of what I do when writing PLC code - so I can't find how to do this in my reference books.
> This is part of a project I'm working on with a Raspberry Pi and an MCP23017 port expander.
> I have a N/O pushbutton that I want to "latch" a value to a variable when it's been pressed.  I have this function that gets called periodically in
> a 'while True' statement:
>
> def button():
>     pushbutton = 0
>    button_value = 0
>     pushbutton=bus.read_byte_data(address,GPIOB)
>     if pushbutton > 0:
>          button_value = 1
>     return button_value
>
> I need button_value to become '1' when the button is pressed and to remain '1' until the entire program (only about 25 lines) ends with a sys.exit()
>
> What do I use to 'latch' button_value?

It depends on whether you can set up your system so that pushing the 
button generates an interrupt. But I know little about R.Pi and less 
about the 'port expander'. If there were an interrupt, you would just 
have to write an interrupt handler. When possible, this is much better 
than polling.

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: "Latching" variables in function Terry Reedy <tjreedy@udel.edu> - 2014-04-09 00:35 -0400

csiph-web