switch.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. This file is part of Verrücktes Gemüse.
  8. Verrücktes Gemüse is free software: you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation, either version 3 of the License, or
  11. (at your option) any later version.
  12. Verrücktes Gemüse is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. --------------------------------------------------------------------------
  19. """
  20. from gpiozero import LED
  21. activMode = 0
  22. modeList = []
  23. class Mode:
  24. def __init__ (self, name, gpio):
  25. self.name = str(name)
  26. self.led = LED(gpio)
  27. self.activ = 0
  28. modeList.append(self)
  29. def ModeOn(self):
  30. """ Activates the Mode """
  31. self.led.on()
  32. self.activ = 1
  33. global activMode
  34. activMode = modeList.index(self)
  35. print ("\n[MODE] - " + self.name + "\n")
  36. def ModeOff(self):
  37. """ Deactivates the Mode """
  38. self.led.off()
  39. self.activ = 0
  40. drums = Mode ("DRUMS", 17)
  41. jokes = Mode ("WITZE", 27)
  42. crazy = Mode ("CRAZY", 22)
  43. modeList[0].ModeOn() # Startmode
  44. def NextMode ():
  45. """ Cecks which Mode is activ, then change to next """
  46. for mode in range(len(modeList)):
  47. if modeList[mode].activ == 1:
  48. modeList[mode].ModeOff()
  49. if mode == len(modeList)-1:
  50. modeList[0].ModeOn() # Return to the first Mode on list
  51. else:
  52. modeList[mode+1].ModeOn() # Activate the next Mode on list
  53. break