File tree Expand file tree Collapse file tree 1 file changed +3
-4
lines changed Expand file tree Collapse file tree 1 file changed +3
-4
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,6 @@ def initialize(pin = nil, **kwargs)
19
19
20
20
def frequency ( freq )
21
21
self . f = freq
22
- print ( self . f )
23
22
ESP32 ::LEDC . set_freq ( self . group , self . timer , self . f )
24
23
end
25
24
@@ -28,12 +27,12 @@ def period_us(micro_sec)
28
27
end
29
28
30
29
def duty ( percent )
31
- self . d = Rational ( percent , 100 ) . to_i
32
- ESP32 ::LEDC . set_duty ( self . group , self . channel , self . d )
30
+ self . d = Rational ( percent , 100 )
31
+ ESP32 ::LEDC . set_duty ( self . group , self . channel , ( self . d * ( 2 ** self . resolution ) ) . to_i )
33
32
end
34
33
35
34
def pulse_width_us ( micro_sec )
36
- us_per_bit = Rational ( 1_000_000 , self . f ) / ( 2 ** self . resolution )
35
+ us_per_bit = Rational ( 1_000_000 , self . f )
37
36
duty ( ( Rational ( micro_sec , us_per_bit ) * 100 ) . to_i )
38
37
end
39
38
end
You can’t perform that action at this time.
0 commit comments