123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- """
- Example Lib
- """
- from machine import Pin, Timer
- class foo(object):
- """
- Example class.
- """
- ############################## Attributes ##############################
- ############################## Constructor ##############################
- def __init__(self,led_pin_time:Pin,led_pin_button:Pin,button:Pin):
- """_summary_
- Args:
- led_pin_time (Pin): _description_
- led_pin_button (Pin): _description_
- button (Pin): _description_
- """
-
- self.__led_pin_timer = self.__check_pin(led_pin_time)
- self.__led_pin_button = self.__check_pin(led_pin_button)
- self.__button = self.__check_pin(button)
- self.__led_pin_timer.init(mode=Pin.OUT)
- self.__led_pin_button.init(mode=Pin.OUT)
- self.__button.init(mode=Pin.IN)
- self.__timer = Timer()
- self.__timer.init(mode=Timer.PERIODIC,period = 200,callback= self.__blink_handler)
- self.__button.irq(handler=self.__int_handler,hard=True,trigger=Pin.IRQ_FALLING)
-
- ############################## Property ##############################
- @property
- def button(self):
- return self.__button
- @button.setter
- def button(self,pin):
- #self.__button = self.__check_pin(pin)
- raise AttributeError("Du darfst Pin nicht verändern")
- ############################## Methods ##############################
-
-
- def __check_pin(self,pin:Pin):
- """_summary_
- Args:
- pin (Pin): _description_
- """
- if not isinstance(pin,Pin):
- raise ValueError(f"Value\"{pin}\" of \"pin\" is not type \"Pin\"!")
- else:
- return pin
- def __blink_handler(self,timer):
- self.__led_pin_timer.toggle()
-
- def __int_handler(self,pin):
- self.__led_pin_button.toggle()
|