Skip to content

Commit

Permalink
PWM is now a function that returns a PwmObject
Browse files Browse the repository at this point in the history
  • Loading branch information
alxwrd committed Aug 18, 2018
1 parent 32aee8a commit 304625e
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions l293d/gpio/micropython.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

import machine

from l293d.driver import v_print


Expand All @@ -13,17 +15,21 @@ 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)

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):
Expand Down

0 comments on commit 304625e

Please sign in to comment.