__init__.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. """
  2. Example Lib
  3. """
  4. from machine import Pin, Timer
  5. class foo(object):
  6. """
  7. Example class.
  8. """
  9. ############################## Attributes ##############################
  10. ############################## Constructor ##############################
  11. def __init__(self,led_pin_time:Pin,led_pin_button:Pin,button:Pin):
  12. """_summary_
  13. Args:
  14. led_pin_time (Pin): _description_
  15. led_pin_button (Pin): _description_
  16. button (Pin): _description_
  17. """
  18. self.__led_pin_timer = self.__check_pin(led_pin_time)
  19. self.__led_pin_button = self.__check_pin(led_pin_button)
  20. self.__button = self.__check_pin(button)
  21. self.__led_pin_timer.init(mode=Pin.OUT)
  22. self.__led_pin_button.init(mode=Pin.OUT)
  23. self.__button.init(mode=Pin.IN)
  24. self.__timer = Timer()
  25. self.__timer.init(mode=Timer.PERIODIC,period = 200,callback= self.__blink_handler)
  26. self.__button.irq(handler=self.__int_handler,hard=True,trigger=Pin.IRQ_FALLING)
  27. ############################## Property ##############################
  28. @property
  29. def button(self):
  30. return self.__button
  31. @button.setter
  32. def button(self,pin):
  33. #self.__button = self.__check_pin(pin)
  34. raise AttributeError("Du darfst Pin nicht verändern")
  35. ############################## Methods ##############################
  36. def __check_pin(self,pin:Pin):
  37. """_summary_
  38. Args:
  39. pin (Pin): _description_
  40. """
  41. if not isinstance(pin,Pin):
  42. raise ValueError(f"Value\"{pin}\" of \"pin\" is not type \"Pin\"!")
  43. else:
  44. return pin
  45. def __blink_handler(self,timer):
  46. self.__led_pin_timer.toggle()
  47. def __int_handler(self,pin):
  48. self.__led_pin_button.toggle()