43 lines
880 B
Python
43 lines
880 B
Python
from typing import Optional
|
|
|
|
|
|
class GPIO:
|
|
BCM = 1
|
|
IN = 1
|
|
OUT = 2
|
|
LOW = 0
|
|
HIGH = 1
|
|
|
|
class PWM:
|
|
def __init__(self, pin, freq):
|
|
self.pin = pin
|
|
self.freq = freq
|
|
self.dc: Optional[float] = None
|
|
self.name = None
|
|
|
|
def start(self, dc: float):
|
|
self.dc = dc
|
|
|
|
def ChangeDutyCycle(self, dc):
|
|
self.dc = dc
|
|
print(f'[{self.pin}@{self.freq}Hz]{" " + self.name if self.name else ""} => {self.dc}')
|
|
|
|
def stop(self):
|
|
print("stop pwm")
|
|
|
|
@staticmethod
|
|
def setup(pin, mode):
|
|
print(f"setup {pin} -> {mode}")
|
|
|
|
@staticmethod
|
|
def output(pin, value):
|
|
print(f"output {pin} -> {value}")
|
|
|
|
@staticmethod
|
|
def setmode(mode):
|
|
print(f"setmode {mode}")
|
|
|
|
@staticmethod
|
|
def cleanup():
|
|
print("cleanup")
|