Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.sys.raspberry-pi > #9508
| From | John McKenzie <davros@bellaliant.net> |
|---|---|
| Subject | RPi.GPIO Button Help Please |
| Newsgroups | comp.sys.raspberry-pi |
| Message-ID | <0e1Ex.10370$wH.2464@fx10.iad> (permalink) |
| Date | 2015-08-28 17:53 +0000 |
Hello, all.
I was very pleasantly surprised to be find out about this newsgroup.
It would be appreciated if anyone here could help me with my GPIO
problems.
I am building a device that has three arcade buttons ("Massive Arcade
Buttons" from Adafruit) attached to a Raspberry Pi via the GPIO pins. The
Pi is attached to a Blinkstick Pro that controls an analog LED light
strip. The idea is that pushing a button will change the LED strip to the
colour of that button and the Pi will record how much time the strip
spends as each colour.
For quick develop purposes I replaced the code that changes the colour
of the LED strip with a print statment. Once I have the buttons working I
will go back to the colour changing code.
It does not work right now. All my variations of the code result in one
of three problems. An error message stating "Conflicting edge detection
already enabled for this GPIO channel", the script running then quiting
in under one second, or sitting there being unresponsive to anything.
Here is the script. This very is unresponsive, unless I remove the sleep
command. When I do that it runs and quits instantly.
import atexit
import time
from blinkstick import blinkstick
import RPi.GPIO as GPIO
led = blinkstick.find_first()
colour = 0
timered = 0
timeyellow = 0
timeblue = 0
timestamp = time.strftime("%H:%M:%S")
GPIO.setmode(GPIO.BCM)
GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
def red_button(channel):
colour = 1
while colour == 1:
print "Red Button pressed"
timered += 1
def yellow_button(channel):
colour = 2
while colour == 2:
print "Yellow Button pressed"
timeyellow += 1
def blue_button(channel):
colour = 3
while colour == 3:
print "Blue Button pressed"
timeblue += 1
GPIO.add_event_detect(23, GPIO.RISING, callback=yellow_button,
bouncetime=200)
GPIO.add_event_detect(22, GPIO.RISING, callback=red_button,
bouncetime=200)
GPIO.add_event_detect(24, GPIO.RISING, callback=blue_button,
bouncetime=200)
while True:
time.sleep(0.1)
def exit_handler():
print '\033[0;41;37mRed Team:\033[0m ', timered
print '\033[0;103;30mYellow Team:\033[0m ', timeyellow
print '\033[0;44;37mBlue Team:\033[0m ', timeblue
flog = open('flag1log.text', 'a')
flog.write(timestamp + '\n' + 'Red Team: ' + str(timered) + '\n' +
'Yellow Team: ' + str(timeyellow) + '\n' + 'Blue Team: ' + str(timeblue)
+ '\n')
flog.close()
atexit.register(exit_handler)
GPIO.cleanup()
Would very much appreciate help getting this working. Thank you.
Back to comp.sys.raspberry-pi | Previous | Next — Next in thread | Find similar | Unroll thread
RPi.GPIO Button Help Please John McKenzie <davros@bellaliant.net> - 2015-08-28 17:53 +0000
Re: RPi.GPIO Button Help Please Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-08-29 13:37 -0400
Re: RPi.GPIO Button Help Please Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-08-29 13:52 -0400
Re: RPi.GPIO Button Help Please John McKenzie <davros@bellaliant.net> - 2015-08-29 18:10 +0000
Re: RPi.GPIO Button Help Please Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-08-30 22:21 -0400
Re: RPi.GPIO Button Help Please John McKenzie <davros@bellaliant.net> - 2015-09-05 19:20 +0000
Re: RPi.GPIO Button Help Please Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-09-06 12:56 -0400
Re: RPi.GPIO Button Help Please Rob Morley <nospam@ntlworld.com> - 2015-09-06 18:16 +0100
Re: RPi.GPIO Button Help Please John McKenzie <davros@bellaliant.net> - 2015-09-09 18:19 +0000
Re: RPi.GPIO Button Help Please Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-09-09 20:33 -0400
Re: RPi.GPIO Button Help Please John McKenzie <davros@bellaliant.net> - 2015-09-10 16:00 +0000
Re: RPi.GPIO Button Help Please John McKenzie <davros@bellaliant.net> - 2015-09-13 06:11 +0000
csiph-web