Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #69960
| From | alister <alister.nospam.ware@ntlworld.com> |
|---|---|
| Subject | Re: "Latching" variables in function |
| Newsgroups | comp.lang.python |
| References | <mailman.9045.1397000922.18130.python-list@python.org> <mailman.9076.1397051608.18130.python-list@python.org> |
| Message-ID | <FUd1v.90724$rf1.40465@fx08.am4> (permalink) |
| Organization | virginmedia.com |
| Date | 2014-04-09 15:43 +0000 |
On Wed, 09 Apr 2014 08:53:19 -0500, Mark H Harris wrote: > On 4/8/14 3:09 PM, Grawburg wrote: > >> I have a N/O pushbutton that I want to "latch" a value to a variable >> when it's been pressed. >> I need button_value to become '1' when the button is pressed and to >> remain '1' until ... > >> What do I use to 'latch' button_value? > > Philosophically speaking buttons don't latch. You push the button, an > event is generated, and the call-back handles the event to do something > in your project. > > You might try setting a global variable on the button-push event. > > Or, if I understand you, you might want to use a configurable, like a > radio button or a check box, either of which are designed to be > "latched". > > > marcus How familiar are you with oop? a class would sort this quite nicely Class Button(object) def __init__(self,bit): self.pressed=False: self.bit=bit def check_button(self): if bus.read_byte_data(bit): self.pressed=True button=Button(address.GPIOB) while not button.pressed: button.check button() once button.pressed has been set True it will remain True until you reset it with button.pressed=False + with a bit of tweaking you should be able to create multiple button objects for each switch you connect *note this code has been typed direct & not tested so may contain minor errors. -- Imbalance of power corrupts and monopoly of power corrupts absolutely. -- Genji
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
"Latching" variables in function Grawburg <grawburg@myglnc.com> - 2014-04-08 16:09 -0400
Re: "Latching" variables in function Denis McMahon <denismfmcmahon@gmail.com> - 2014-04-09 00:28 +0000
Re: "Latching" variables in function Mark H Harris <harrismh777@gmail.com> - 2014-04-09 08:53 -0500
Re: "Latching" variables in function alister <alister.nospam.ware@ntlworld.com> - 2014-04-09 15:43 +0000
csiph-web