-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPCA9685.py
34 lines (26 loc) · 1.18 KB
/
PCA9685.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
""" This class is an instance of a single PCA9685 board PWM channel """
import sys
sys.path.append('./aeac_controls_2022/')
from constants import I2C_BUS
from utils import getCounterValues
from pwm import PWM
class PCA9685:
def __init__(self, channel, freq, debug=False):
self.freq = freq
self.current_state = 0 #
self.channel = channel
self.debug = debug
def reset(self, pwm):
# reset PCA9685
if self.debug:
print("Reseting PCA9685")
on_count, off_count = getCounterValues(delay=0, dc=0)
on_hex, off_hex = int(hex(on_count), base=16), int(hex(off_count), base=16)
pwm.setPWMCounters(self.channel, I2C_BUS, on_hex, off_hex) # EN = 0
def setPWM(self, pwm, dutycycle, delay=0):
on_count, off_count = getCounterValues(delay, dutycycle)
on_hex, off_hex = int(hex(on_count), base=16), int(hex(off_count), base=16)
if self.debug:
print("Delay: {}, Duty Cycle: {}".format(delay, dutycycle))
print("ON: {}, {}, OFF: {}, {}".format(on_count, hex(on_count), off_count, hex(off_count)))
pwm.setPWMCounters(self.channel, I2C_BUS, on_hex, off_hex)