class Beaglebone::PWMPin
Object Oriented PWM
Implementation. This treats the pin as an object.
Public Class Methods
Initialize a PWM
pin
@param duty should specify the duty cycle @param frequency should specify cycles per second @param polarity optional, should specify the polarity, :NORMAL or :INVERTED @param run optional, if false, pin will be configured but will not run
@example
p9_14 = PWMPin.new(:P9_14, 90, 10, :NORMAL)
# File lib/beaglebone/pwm.rb, line 416 def initialize(pin, duty=nil, frequency=nil, polarity=nil, run=true) @pin = pin PWM::start(@pin, duty, frequency, polarity, run) end
Public Instance Methods
Disable PWM
pin
# File lib/beaglebone/pwm.rb, line 478 def disable_pwm_pin PWM::disable_pwm_pin(@pin) end
Start PWM
output on pin. Pin must have been previously started
# File lib/beaglebone/pwm.rb, line 427 def run PWM::run(@pin) end
Set duty cycle of pin in percentage
@param duty should specify the duty cycle in percentage @example
p9_14.set_duty_cycle(25)
# File lib/beaglebone/pwm.rb, line 446 def set_duty_cycle(duty, newperiod=nil) PWM::set_duty_cycle(@pin, duty, newperiod) end
Set duty cycle of pin in nanoseconds
@param duty should specify the duty cycle in nanoseconds @example
p9_14.set_duty_cycle_ns(2500000)
# File lib/beaglebone/pwm.rb, line 455 def set_duty_cycle_ns(duty) PWM::set_duty_cycle_ns(@pin, duty) end
Set frequency of pin in cycles per second
@param frequency should specify the frequency in cycles per second @example
p9_14.set_frequency(100)
# File lib/beaglebone/pwm.rb, line 464 def set_frequency(frequency) PWM::set_frequency(@pin, frequency) end
Set frequency of pin based on period duration
@param period should specify the length of a cycle in nanoseconds @example
p9_14.set_frequency_ns(100000000)
# File lib/beaglebone/pwm.rb, line 473 def set_period_ns(period) PWM::set_period_ns(@pin, period) end
Set polarity on pin
@param polarity should specify the polarity, :NORMAL or :INVERTED @example
p9_14.set_polarity(:INVERTED)
# File lib/beaglebone/pwm.rb, line 436 def set_polarity(polarity) PWM::set_polarity(@pin, polarity) end
Stop PWM
output on pin
# File lib/beaglebone/pwm.rb, line 422 def stop PWM::stop(@pin) end