Micropython Classes in separate Files
Posted: Thu Mar 24, 2022 8:00 pm
When classes are in separate files there are no errors but the program does nothing. Pycharm recognises the BlinkerClass for code complete. On a Pico if that helps. Thanks
>>>File: main.py
>>>File: blinker.py
Note 1: @staticmethod is needed else an error!!
Note 2: if def blink(pin): is changed to def blink(self, pin): another error
>>>File: main.py
Code: Select all
import blinker
if __name__ == "__main__":
b = blinker.BlinkerClass()
b.blink(25)
Code: Select all
import time
from machine import Pin
class BlinkerClass:
@staticmethod
def blink(pin):
led = Pin(pin, Pin.OUT)
while True:
led.value(1)
time.sleep(0.5)
led.value(0)
time.sleep(2)
Note 2: if def blink(pin): is changed to def blink(self, pin): another error