From 304625ea9731d9d7179815cadcb5dfe2d66793f1 Mon Sep 17 00:00:00 2001 From: Alex Ward Date: Sat, 18 Aug 2018 16:50:50 +0100 Subject: [PATCH] PWM is now a function that returns a PwmObject --- l293d/gpio/micropython.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/l293d/gpio/micropython.py b/l293d/gpio/micropython.py index 7af9a81..c7e958c 100644 --- a/l293d/gpio/micropython.py +++ b/l293d/gpio/micropython.py @@ -1,4 +1,6 @@ +import machine + from l293d.driver import v_print @@ -13,9 +15,9 @@ class GPIO(object): BOARD = "BOARD" BCM = "BCM" - class PWM(object): - def __init__(self, pin_num, freq): - self.pin = GPIO._GPIO__pins[pin_num] + class PwmObject(object): + def __init__(self, pin, freq): + self.pin = pin self.pwm = machine.PWM(self.pin) self.pwm.freq(freq) @@ -23,7 +25,11 @@ def start(self, duty): self.pwm.duty(duty) def stop(self): - self.pwn.deinit() + self.pwm.deinit() + + @classmethod + def PWM(cls, pin, freq): + return cls.PwmObject(cls.__pins[pin], freq) @classmethod def setwarnings(cls, warn):