switch.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. Created on Thu Jan 30 18:16:23 2019
  5. @author: moetom
  6. """
  7. from gpiozero import LED
  8. activMode = 0
  9. modeList = []
  10. class Mode:
  11. def __init__ (self, name, gpio):
  12. self.name = str(name)
  13. self.led = LED(gpio)
  14. self.activ = 0
  15. modeList.append(self)
  16. def ModeOn(self):
  17. """ Activates the Mode """
  18. self.led.on()
  19. self.activ = 1
  20. global activMode
  21. activMode = modeList.index(self)
  22. print ("\n[MODE] - " + self.name + "\n")
  23. def ModeOff(self):
  24. """ Deactivates the Mode """
  25. self.led.off()
  26. self.activ = 0
  27. drums = Mode ("DRUMS", 17)
  28. jokes = Mode ("WITZE", 27)
  29. crazy = Mode ("CRAZY", 22)
  30. modeList[0].ModeOn() # Startmode
  31. def NextMode ():
  32. """ Cecks which Mode is activ, then change to next """
  33. for mode in range(len(modeList)):
  34. if modeList[mode].activ == 1:
  35. modeList[mode].ModeOff()
  36. if mode == len(modeList)-1:
  37. modeList[0].ModeOn() # Return to the first Mode on list
  38. else:
  39. modeList[mode+1].ModeOn() # Activate the next Mode on list
  40. break