Class: Beaglebone::PWMPin
- Inherits:
-
Object
- Object
- Beaglebone::PWMPin
- Defined in:
- lib/beaglebone/pwm.rb
Overview
Object Oriented PWM Implementation. This treats the pin as an object.
Instance Method Summary collapse
-
#disable_pwm_pin ⇒ Object
Disable PWM pin.
-
#initialize(pin, duty = nil, frequency = nil, polarity = nil, run = true) ⇒ PWMPin
constructor
Initialize a PWM pin.
-
#run ⇒ Object
Start PWM output on pin.
-
#set_duty_cycle(duty, newperiod = nil) ⇒ Object
Set duty cycle of pin in percentage.
-
#set_duty_cycle_ns(duty) ⇒ Object
Set duty cycle of pin in nanoseconds.
-
#set_frequency(frequency) ⇒ Object
Set frequency of pin in cycles per second.
-
#set_period_ns(period) ⇒ Object
Set frequency of pin based on period duration.
-
#set_polarity(polarity) ⇒ Object
Set polarity on pin.
-
#stop ⇒ Object
Stop PWM output on pin.
Constructor Details
#initialize(pin, duty = nil, frequency = nil, polarity = nil, run = true) ⇒ PWMPin
Initialize a PWM pin
416 417 418 419 |
# 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 |
Instance Method Details
#disable_pwm_pin ⇒ Object
Disable PWM pin
478 479 480 |
# File 'lib/beaglebone/pwm.rb', line 478 def disable_pwm_pin PWM::disable_pwm_pin(@pin) end |
#run ⇒ Object
Start PWM output on pin. Pin must have been previously started
427 428 429 |
# File 'lib/beaglebone/pwm.rb', line 427 def run PWM::run(@pin) end |
#set_duty_cycle(duty, newperiod = nil) ⇒ Object
Set duty cycle of pin in percentage
446 447 448 |
# 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) ⇒ Object
Set duty cycle of pin in nanoseconds
455 456 457 |
# File 'lib/beaglebone/pwm.rb', line 455 def set_duty_cycle_ns(duty) PWM::set_duty_cycle_ns(@pin, duty) end |
#set_frequency(frequency) ⇒ Object
Set frequency of pin in cycles per second
464 465 466 |
# File 'lib/beaglebone/pwm.rb', line 464 def set_frequency(frequency) PWM::set_frequency(@pin, frequency) end |
#set_period_ns(period) ⇒ Object
Set frequency of pin based on period duration
473 474 475 |
# File 'lib/beaglebone/pwm.rb', line 473 def set_period_ns(period) PWM::set_period_ns(@pin, period) end |
#set_polarity(polarity) ⇒ Object
Set polarity on pin
436 437 438 |
# File 'lib/beaglebone/pwm.rb', line 436 def set_polarity(polarity) PWM::set_polarity(@pin, polarity) end |
#stop ⇒ Object
Stop PWM output on pin
422 423 424 |
# File 'lib/beaglebone/pwm.rb', line 422 def stop PWM::stop(@pin) end |