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.