File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -78,6 +78,8 @@ def duty_cycle(self) -> int:
7878 pwm = self ._pca .pwm_regs [self ._index ]
7979 if pwm [0 ] == 0x1000 :
8080 return 0xFFFF
81+ if pwm [1 ] == 0x1000 :
82+ return 0x0000
8183 return pwm [1 ] << 4
8284
8385 @duty_cycle .setter
@@ -86,10 +88,16 @@ def duty_cycle(self, value: int) -> None:
8688 raise ValueError (f"Out of range: value { value } not 0 <= value <= 65,535" )
8789
8890 if value == 0xFFFF :
91+ # Special case for "fully on":
8992 self ._pca .pwm_regs [self ._index ] = (0x1000 , 0 )
93+ elif value < 0x0010 :
94+ # Special case for "fully off":
95+ self ._pca .pwm_regs [self ._index ] = (0 , 0x1000 )
9096 else :
9197 # Shift our value by four because the PCA9685 is only 12 bits but our value is 16
92- value = (value + 1 ) >> 4
98+ value = value >> 4
99+ # value should never be zero here because of the test for the "fully off" case
100+ # (the LEDn_ON and LEDn_OFF registers should never be set with the same values)
93101 self ._pca .pwm_regs [self ._index ] = (0 , value )
94102
95103
You can’t perform that action at this time.
0 commit comments