Skip to content
This repository was archived by the owner on Sep 30, 2019. It is now read-only.

Use PCA9685 auto increment #101

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions Adafruit_PWM_Servo_Driver/Adafruit_PWM_Servo_Driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ class PWM :
__ALL_LED_OFF_H = 0xFD

# Bits
__RESTART = 0x80
__SLEEP = 0x10
__ALLCALL = 0x01
__INVRT = 0x10
__OUTDRV = 0x04
__RESTART = 1 << 7
__AI = 1 << 5
__SLEEP = 1 << 4
__ALLCALL = 1 << 0

__INVRT = 1 << 4
__OUTDRV = 1 << 2

general_call_i2c = Adafruit_I2C(0x00)

Expand All @@ -45,10 +47,10 @@ def __init__(self, address=0x40, debug=False):
self.address = address
self.debug = debug
if (self.debug):
print "Reseting PCA9685 MODE1 (without SLEEP) and MODE2"
print "Reseting PCA9685 MODE1 (without SLEEP, but with AI) and MODE2"
self.setAllPWM(0, 0)
self.i2c.write8(self.__MODE2, self.__OUTDRV)
self.i2c.write8(self.__MODE1, self.__ALLCALL)
self.i2c.write8(self.__MODE1, self.__ALLCALL | self.__AI)
time.sleep(0.005) # wait for oscillator

mode1 = self.i2c.readU8(self.__MODE1)
Expand Down Expand Up @@ -79,14 +81,8 @@ def setPWMFreq(self, freq):

def setPWM(self, channel, on, off):
"Sets a single PWM channel"
self.i2c.write8(self.__LED0_ON_L+4*channel, on & 0xFF)
self.i2c.write8(self.__LED0_ON_H+4*channel, on >> 8)
self.i2c.write8(self.__LED0_OFF_L+4*channel, off & 0xFF)
self.i2c.write8(self.__LED0_OFF_H+4*channel, off >> 8)
self.i2c.writeList(self.__LED0_ON_L+4*channel, [on & 0xFF, on >> 8, off & 0xFF, off >> 8])

def setAllPWM(self, on, off):
"Sets a all PWM channels"
self.i2c.write8(self.__ALL_LED_ON_L, on & 0xFF)
self.i2c.write8(self.__ALL_LED_ON_H, on >> 8)
self.i2c.write8(self.__ALL_LED_OFF_L, off & 0xFF)
self.i2c.write8(self.__ALL_LED_OFF_H, off >> 8)
self.i2c.writeList(self.__ALL_LED_ON_L, [on & 0xFF, on >> 8, off & 0xFF, off >> 8])