Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #96379
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!usenetcore.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!nzpost1.xs4all.net!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.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'elif': 0.04; 'handler': 0.04; '#if': 0.05; 'none:': 0.05; '#define': 0.07; 'exit': 0.07; '(0,': 0.09; 'exited': 0.09; 'globals': 0.09; 'message-id:@4ax.com': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'timestamp': 0.09; 'subject:Help': 0.10; 'thread': 0.10; 'def': 0.13; '"a")': 0.16; '"global"': 0.16; '0.0,': 0.16; '23,': 0.16; 'atexit': 0.16; 'call?': 0.16; 'instances,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'statements,': 0.16; 'team:': 0.16; 'time.time()': 0.16; 'url:home': 0.18; '2015': 0.20; 'delta': 0.22; 'sep': 0.22; 'import': 0.24; 'header:X-Complaints- To:1': 0.26; 'skip:" 20': 0.26; 'fri,': 0.27; 'blocking': 0.29; 'loop,': 0.29; "i'm": 0.30; 'print': 0.30; 'creating': 0.30; 'skip:g 30': 0.30; 'run': 0.33; 'class': 0.33; 'channel': 0.34; 'so,': 0.35; 'next': 0.35; 'done': 0.35; 'false': 0.35; 'saved': 0.35; 'but': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'received:org': 0.37; 'charset:us-ascii': 0.37; 'doing': 0.38; 'busy': 0.38; "won't": 0.38; 'button': 0.38; 'skip:p 20': 0.38; 'does': 0.39; 'rather': 0.39; 'to:addr:python.org': 0.40; 'still': 0.40; 'called': 0.40; 'future': 0.60; 'determine': 0.61; 'john': 0.61; 'account': 0.66; 'results': 0.66; 'color': 0.67; 'online': 0.71; 'led': 0.72; 'rgb': 0.84; 'colour': 0.91; 'dennis': 0.91; 'received:108': 0.93 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
| Subject | Re: RPI.GPIO Help |
| Date | Fri, 11 Sep 2015 21:10:46 -0400 |
| Organization | IISS Elusive Unicorn |
| References | <lG5Ax.73238$E26.47630@fx20.iad> <MKhIx.9889$6l6.5720@fx08.iad> <V%EIx.91820$zz6.84582@fx04.iad> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | adsl-108-68-178-61.dsl.klmzmi.sbcglobal.net |
| X-Newsreader | Forte Agent 6.00/32.1186 |
| X-No-Archive | YES |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| 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.387.1442020255.8327.python-list@python.org> (permalink) |
| Lines | 102 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1442020255 news.xs4all.nl 23725 [2001:888:2000:d::a6]:42370 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:96379 |
Show key headers only | View raw
On Fri, 11 Sep 2015 18:24:53 GMT, John McKenzie <davros@bellaliant.net>
declaimed the following:
Take into account that I still don't have an R-Pi, so I'm basing all
this on the online documentation. I still don't like all the "global"
statements, but creating class instances, and blocking queues rather
than the busy-loop can be saved for the future
import atexit
import time
from blinkstick import blinkstick
import RPi.GPIO as GPIO
#define "constants" so updates only need to be done once
(R, G, B) = (0, 1, 2) #G is also being used for Y
(REDCH, YELLOWCH, BLUECH) = (22, 23, 24)
RGB = ("#FF0000", "#FF6000", "#0000FF")
led = blinkstick.find_first()
colour = None
changeTime = None
cumTime = (0.0, 0.0, 0.0)
timestamp = time.strftime("%H:%M:%S")
GPIO.setmode(GPIO.BCM)
GPIO.setup(REDCH, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(YELLOWCH, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(BLUECH, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def buttonHandler(channel):
global colour
global changeTime
# get current time
now = time.time()
# determine if a change in color is called for
if colour != R and channel == REDCH:
newColour = R
elif colour != G and channel == YELLOWCH:
newColour = G
elif colour != B and channel == BLUECH:
newColour = B
else:
return #do nothing with LED
#if first time button pressed, no cumulative time
if changeTime is not None:
#save delta time from last change to this change
cumTime[colour] += now - changeTime
#set globals for next button action
changeTime = now
colour = newColour
#activate LED -- is this a blocking call? if so, other
#button presses won't respond until after this
#finishes
led.pulse(hex=RGB[colour], repeats=1,
duration=2000, steps=50)
GPIO.add_event_detect(REDCH, GPIO.FALLING,
callback=buttonHandler, bouncetime=200)
GPIO.add_event_detect(YELLOWCH, GPIO.FALLING,
callback=buttonHandler, bouncetime=200)
GPIO.add_event_detect(BLUECH, GPIO.FALLING,
callback=buttonHandler, bouncetime=200)
def exit_handler():
# all the exit handler does is set a flag to break out the main
# endless loop, letting the main thread clean up
global keepLooping
keepLooping = False
atexit.register(exit_handler)
keepLooping = True
while keepLooping:
time.sleep(0.1) #eat time doing nothing
# busy loop has exited because atexit handler has set the it False
# so dump the results of this run
led.set_color(name="black")
print "\033[0;41;37mRed Team:\033[0m ", cumTime[R]
print "\033[0;43;30mYellow Time:\033[0m ", cumTime[G]
print "\033[0;44;37mBlue Time:\033[0m ", cumTime[B]
flog = open("flag1.log", "a")
flog.write("%s\nRed Team: %s\nYellow Team: %s\nBlue Team:%s\n"
% (timestamp, cumTime[R], cumTime[G], cumTime[B]))
flog.close()
GPIO.cleanup()
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
RPI.GPIO Help John McKenzie <davros@bellaliant.net> - 2015-08-16 19:40 +0000
Re: RPI.GPIO Help MRAB <python@mrabarnett.plus.com> - 2015-08-16 21:15 +0100
Re: RPI.GPIO Help John McKenzie <davros@bellaliant.net> - 2015-08-20 15:12 +0000
Re: RPI.GPIO Help MRAB <python@mrabarnett.plus.com> - 2015-08-20 16:45 +0100
Re: RPI.GPIO Help alister <alister.nospam.ware@ntlworld.com> - 2015-08-20 15:54 +0000
Re: RPI.GPIO Help Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-08-20 21:27 -0400
Re: RPI.GPIO Help John McKenzie <davros@bellaliant.net> - 2015-08-28 17:40 +0000
Re: RPI.GPIO Help hakugin.gin@gmail.com - 2015-08-28 13:56 -0700
Re: RPI.GPIO Help Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-08-29 14:21 -0400
Re: RPI.GPIO Help John McKenzie <davros@bellaliant.net> - 2015-08-31 17:41 +0000
Re: RPI.GPIO Help hakugin.gin@gmail.com - 2015-08-31 11:25 -0700
Re: RPI.GPIO Help MRAB <python@mrabarnett.plus.com> - 2015-08-31 19:34 +0100
Re: RPI.GPIO Help Johannes Bauer <dfnsonfsduifb@gmx.de> - 2015-09-01 10:58 +0200
Re: RPI.GPIO Help Tim Daneliuk <tundra@bogus-city.tundraware.com> - 2015-08-31 14:07 -0500
Re: RPI.GPIO Help Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-09-01 02:08 -0400
Re: RPI.GPIO Help John McKenzie <davros@bellaliant.net> - 2015-09-02 18:50 +0000
Re: RPI.GPIO Help John McKenzie <davros@bellaliant.net> - 2015-09-09 19:03 +0000
Re: RPI.GPIO Help MRAB <python@mrabarnett.plus.com> - 2015-09-09 20:29 +0100
Re: RPI.GPIO Help John McKenzie <davros@bellaliant.net> - 2015-09-10 15:56 +0000
Re: RPI.GPIO Help John McKenzie <davros@bellaliant.net> - 2015-09-11 18:24 +0000
Re: RPI.GPIO Help MRAB <python@mrabarnett.plus.com> - 2015-09-11 19:49 +0100
Re: RPI.GPIO Help hakugin.gin@gmail.com - 2015-09-11 12:00 -0700
Re: RPI.GPIO Help hakugin.gin@gmail.com - 2015-09-11 12:24 -0700
Re: RPI.GPIO Help Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-09-11 21:10 -0400
Re: RPI.GPIO Help John McKenzie <davros@bellaliant.net> - 2015-09-13 06:08 +0000
Re: RPI.GPIO Help Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-09-13 12:24 -0400
Re: RPI.GPIO Help hakugin.gin@gmail.com - 2015-09-14 05:53 -0700
csiph-web