@@ -26,11 +26,13 @@ class PWM :
26
26
__ALL_LED_OFF_H = 0xFD
27
27
28
28
# Bits
29
- __RESTART = 0x80
30
- __SLEEP = 0x10
31
- __ALLCALL = 0x01
32
- __INVRT = 0x10
33
- __OUTDRV = 0x04
29
+ __RESTART = 1 << 7
30
+ __AI = 1 << 5
31
+ __SLEEP = 1 << 4
32
+ __ALLCALL = 1 << 0
33
+
34
+ __INVRT = 1 << 4
35
+ __OUTDRV = 1 << 2
34
36
35
37
general_call_i2c = Adafruit_I2C (0x00 )
36
38
@@ -45,10 +47,10 @@ def __init__(self, address=0x40, debug=False):
45
47
self .address = address
46
48
self .debug = debug
47
49
if (self .debug ):
48
- print "Reseting PCA9685 MODE1 (without SLEEP) and MODE2"
50
+ print "Reseting PCA9685 MODE1 (without SLEEP, but with AI ) and MODE2"
49
51
self .setAllPWM (0 , 0 )
50
52
self .i2c .write8 (self .__MODE2 , self .__OUTDRV )
51
- self .i2c .write8 (self .__MODE1 , self .__ALLCALL )
53
+ self .i2c .write8 (self .__MODE1 , self .__ALLCALL | self . __AI )
52
54
time .sleep (0.005 ) # wait for oscillator
53
55
54
56
mode1 = self .i2c .readU8 (self .__MODE1 )
@@ -79,14 +81,8 @@ def setPWMFreq(self, freq):
79
81
80
82
def setPWM (self , channel , on , off ):
81
83
"Sets a single PWM channel"
82
- self .i2c .write8 (self .__LED0_ON_L + 4 * channel , on & 0xFF )
83
- self .i2c .write8 (self .__LED0_ON_H + 4 * channel , on >> 8 )
84
- self .i2c .write8 (self .__LED0_OFF_L + 4 * channel , off & 0xFF )
85
- self .i2c .write8 (self .__LED0_OFF_H + 4 * channel , off >> 8 )
84
+ self .i2c .writeList (self .__LED0_ON_L + 4 * channel , [on & 0xFF , on >> 8 , off & 0xFF , off >> 8 ])
86
85
87
86
def setAllPWM (self , on , off ):
88
87
"Sets a all PWM channels"
89
- self .i2c .write8 (self .__ALL_LED_ON_L , on & 0xFF )
90
- self .i2c .write8 (self .__ALL_LED_ON_H , on >> 8 )
91
- self .i2c .write8 (self .__ALL_LED_OFF_L , off & 0xFF )
92
- self .i2c .write8 (self .__ALL_LED_OFF_H , off >> 8 )
88
+ self .i2c .writeList (self .__ALL_LED_ON_L , [on & 0xFF , on >> 8 , off & 0xFF , off >> 8 ])
0 commit comments