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:
78
78
pwm = self ._pca .pwm_regs [self ._index ]
79
79
if pwm [0 ] == 0x1000 :
80
80
return 0xFFFF
81
+ if pwm [1 ] == 0x1000 :
82
+ return 0x0000
81
83
return pwm [1 ] << 4
82
84
83
85
@duty_cycle .setter
@@ -86,10 +88,16 @@ def duty_cycle(self, value: int) -> None:
86
88
raise ValueError (f"Out of range: value { value } not 0 <= value <= 65,535" )
87
89
88
90
if value == 0xFFFF :
91
+ # Special case for "fully on":
89
92
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 )
90
96
else :
91
97
# 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)
93
101
self ._pca .pwm_regs [self ._index ] = (0 , value )
94
102
95
103
You can’t perform that action at this time.
0 commit comments