John McKenzie davros at bellaliant.net
Thu Aug 20 17:12:37 CEST 2015

 Thanks for the reply. Also, thanks to Laura who replied via email.

 Tried a bunch of things based off these comments and I always ended up 
with one of two situations, the channel conflict error, or an instant run 
and quit issue. This new version of the code runs but is unresponsive. I 
removed loops then put in a short sleep loop. while True:
    time.sleep(0.1) It could be my hardware is done up wrong, but it 
looks OK. Perhaps it is always sleeping.

 Anyone at all know about GPIO and the Pi under the Python library 
RPi.GPIO please feel free to advise as to what the problem is most likely 
to be.

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.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, 
GPIO.add_event_detect(22, GPIO.RISING, callback=red_button, 
GPIO.add_event_detect(24, GPIO.RISING, callback=blue_button, 

while True:

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')


More information about the Python-list mailing list