class Beaglebone::PWMPin

Object Oriented PWM Implementation. This treats the pin as an object.

Public Class Methods

new(pin, duty=nil, frequency=nil, polarity=nil, run=true) click to toggle source

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() click to toggle source

Disable PWM pin

# File lib/beaglebone/pwm.rb, line 478
def disable_pwm_pin
  PWM::disable_pwm_pin(@pin)
end
run() click to toggle source

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(duty, newperiod=nil) click to toggle source

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_ns(duty) click to toggle source

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(frequency) click to toggle source

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_period_ns(period) click to toggle source

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(polarity) click to toggle source

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() click to toggle source

Stop PWM output on pin

# File lib/beaglebone/pwm.rb, line 422
def stop
  PWM::stop(@pin)
end