Advertisement
gPiOBox

Further Project - Quiz - Lighting code

Nov 26th, 2017
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.49 KB | None | 0 0
  1. """
  2. filename:gpio_RPi_quiz_lighting.py
  3. Further Project - Quiz  - Lighting code
  4. written by Trevor Olsson
  5. © GPIO Support Services LTD MMXVII
  6. More info here: https://www.gpio.co.uk/quiz
  7. and here: https://gpiozero.readthedocs.io/en/stable/api_boards.html
  8. """
  9. from gpiozero import LEDBoard, Button
  10. from time import sleep
  11.  
  12. BtnA1 = Button(4,pull_up=False)
  13. BtnA2 = Button(14,pull_up=False)
  14. BtnA3 = Button(15,pull_up=False)
  15. BtnA4 = Button(25,pull_up=False)
  16. TeamALights = LEDBoard(17,18,27,22)
  17. TeamBLights = LEDBoard(23,24)
  18. AllLights = LEDBoard(TeamALights,TeamBLights)
  19.  
  20. while True:
  21.     Current_team=0 #This is Current Team flag; 1 is Team A answering, 2 is Team B, 0 is Starter Question - on live system this value is acquired from 'Scoring' code
  22.     if Current_team==0:
  23.         AllLights.on()
  24.         if BtnA1.is_pressed:
  25.             TeamALights.value = (1,0,0,0)
  26.             TeamBLights.off()
  27.             sleep(1)
  28.         if BtnA2.is_pressed:
  29.             TeamALights.value = (0,1,0,0)
  30.             TeamBLights.off()
  31.             sleep(1)
  32.         if BtnA3.is_pressed:
  33.             TeamALights.value = (0,0,1,0)
  34.             TeamBLights.off()
  35.             sleep(1)
  36.         if BtnA4.is_pressed:
  37.             TeamALights.value = (0,0,0,1)
  38.             TeamBLights.off()
  39.             sleep(1)
  40.     elif Current_team==1:
  41.         TeamALights.on()
  42.         TeamBLights.off()
  43.         sleep(1)
  44.     elif Current_team==2:
  45.         TeamBLights.on()
  46.         TeamALights.off()
  47.         sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement