# Progress the light print("Light going amber!") pibrella.light.amber.on() pibrella.light.green.off() current_light = 'amber' # Small delay time.sleep(0.5) # Progress the light print("Light going red!") current_light = 'red' # I felt it was harsh on fast # reaction times time.sleep(0.1) red_time = time.time() pibrella.light.red.on() pibrella.light.amber.off() # Wait for the button to be pressed while button_pressed == False: time.sleep(0.1) pibrella.loop(random_lights) pibrella.pause()
print("Light going amber!") pibrella.light.amber.on() pibrella.light.green.off() current_light = 'amber' # Small delay time.sleep(0.5) # Progress the light print("Light going red!") current_light = 'red' # I felt it was harsh on fast # reaction times time.sleep(0.1) red_time = time.time() pibrella.light.red.on() pibrella.light.amber.off() # Wait for the button to be pressed while button_pressed == False: time.sleep(0.1) pibrella.loop(random_lights) pibrella.pause()
import pibrella import time pibrella.output.h.on(); print "Wait for it!" time.sleep(0.5) def ping(): time.sleep(0.2) pibrella.output.g.on() time.sleep(0.00001) pibrella.output.g.off() #print "Fired!" #time.sleep(1) #pibrella.light.green.on() while (pibrella.input.d.read() == 0): pulse_start = time.time() while (pibrella.input.d.read() == 1): pulse_end = time.time() pibrella.light.off() pulse_duration = pulse_end - pulse_start distance = pulse_duration * 34000 / 2 #17150 print "Distance: %.1f cm" % distance pibrella.loop(ping) pibrella.pause()
pibrella.buzzer.off() def waitingForFlash(): global running, start_time, MAX_TIME, GO_TIME, GO_DURATION, correct_flash_detected # This loop is continuously called while waiting for # asynch input. It is needed to be able to catch the # time out case. while running: elapsed_time = time.time() - start_time if elapsed_time > GO_TIME and elapsed_time < GO_TIME + GO_DURATION: # This should only happen once pibrella.light.green.on() time.sleep(FLASH_DURATION) pibrella.light.green.off() elif elapsed_time > MAX_TIME: if correct_flash_detected: print("Flash stayed on too long!") else: print("Flash started too Late!") print(elapsed_time) reportStatus(False) time.sleep(0.01) pibrella.button.pressed(start) pibrella.input.d.changed(alarm) # TBD need a function that the server calls to start start(pibrella.button) pibrella.loop(waitingForFlash) pibrella.pause()
#start pin sequence subprocess.call(["/home/pi/startall.sh"]) else: pibrella.light.yellow.off() #light turns off when shutdown happens print("Shutdown!") #do the shutdown #subprocess.call(["echo", "shutdown -h now"]) subprocess.call(["/usr/bin/shutdown", "-h", "now"]) def lighttransition(): global presstime time.sleep(.1) #has the program wait if pibrella.button.read() == 1 or pibrella.input.a.read() == 1: #above line checks both of the buttons for changes time.sleep(.1) currenttime = time.time() timedifference = currenttime - presstime #print(timedifference, currenttime, presstime) if timedifference > 3.: #the transition between the lights to show what is going on pibrella.light.green.off() pibrella.light.yellow.on() #turns red led on to show that the program is running pibrella.light.red.on() pibrella.button.changed(button_changed) #calling the functions pibrella.input.a.changed(button_changed) #has it run the button changed function when the wired button is pressed pibrella.loop(lighttransition) pibrella.pause()