Class: PiPiper::Pwm
- Inherits:
-
Object
- Object
- PiPiper::Pwm
- Defined in:
- lib/pi_piper/pwm.rb
Overview
Represents a Pwm output on the Raspberry Pi (only GPIO18 is avaliable on header)
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(options) ⇒ Pwm
constructor
Initializes a new PWM pin.
-
#off ⇒ Object
(also: #stop)
Stop the Pwm signal.
- #off? ⇒ Boolean
-
#on ⇒ Object
(also: #start)
Start the Pwm signal.
- #on? ⇒ Boolean
Constructor Details
#initialize(options) ⇒ Pwm
Initializes a new PWM pin.
either :balanced or :markspace but depends from driver. Defaults to :balanced.
Defaults to 19.2Mhz.
for the value. Defaults to 1024.
Defaults to 0.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/pi_piper/pwm.rb', line 24 def initialize() @options = { :mode => :balanced, :clock => 19.2.megahertz, :range => 1024, :value => 0, }.merge() PiPiper.driver.pwm_set_pin(@options[:pin]) PiPiper.driver.pwm_set_clock(get_clock_divider(@options[:clock])) PiPiper.driver.pwm_set_range(@options[:pin], [:range]) self.value= @options.delete(:value) PiPiper.driver.pwm_set_mode(@options[:pin], [:mode]) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/pi_piper/pwm.rb', line 5 def @options end |
#value ⇒ Object
Returns the value of attribute value.
5 6 7 |
# File 'lib/pi_piper/pwm.rb', line 5 def value @value end |
Instance Method Details
#off ⇒ Object Also known as: stop
Stop the Pwm signal
53 54 55 56 |
# File 'lib/pi_piper/pwm.rb', line 53 def off @on = false PiPiper.driver.pwm_set_mode(@options[:pin], [:mode], 0) #check if compatible with other driver than bcm2835 end |
#off? ⇒ Boolean
64 65 66 |
# File 'lib/pi_piper/pwm.rb', line 64 def off? not on? end |
#on ⇒ Object Also known as: start
Start the Pwm signal
44 45 46 47 |
# File 'lib/pi_piper/pwm.rb', line 44 def on @on = true PiPiper.driver.pwm_set_mode(@options[:pin], [:mode], 1) #check if compatible with other driver than bcm2835 end |
#on? ⇒ Boolean
60 61 62 |
# File 'lib/pi_piper/pwm.rb', line 60 def on? @on end |