Class: PiPiper::Pwm
Overview
Represents a Pwm output on the Raspberry Pi (only GPIO18 is avaliable on header)
Constant Summary
Constants included from PinValues
PiPiper::PinValues::GPIO_FSEL_ALT0, PiPiper::PinValues::GPIO_FSEL_ALT1, PiPiper::PinValues::GPIO_FSEL_ALT2, PiPiper::PinValues::GPIO_FSEL_ALT3, PiPiper::PinValues::GPIO_FSEL_ALT4, PiPiper::PinValues::GPIO_FSEL_ALT5, PiPiper::PinValues::GPIO_FSEL_INPT, PiPiper::PinValues::GPIO_FSEL_MASK, PiPiper::PinValues::GPIO_FSEL_OUTP, PiPiper::PinValues::GPIO_HIGH, PiPiper::PinValues::GPIO_LOW, PiPiper::PinValues::GPIO_PUD_DOWN, PiPiper::PinValues::GPIO_PUD_OFF, PiPiper::PinValues::GPIO_PUD_UP, PiPiper::PinValues::PWM_MODE, PiPiper::PinValues::PWM_PIN
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.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/pi_piper/pwm.rb', line 15 def initialize() @options = { :mode => :balanced, :clock => 19.2.megahertz, :range => 1024, :start => true, :value => 0 }.merge() unless PWM_PIN[@options[:pin]] raise ArgumentError, ":pin should be one of #{PWM_PIN.keys} not #{@options[:pin]}" end unless PWM_MODE.include? @options[:mode] raise ArgumentError, ":mode should be one of #{PWM_MODE}, not #{@options[:mode]}" end self.value= @options.delete(:value) self.pin= @options[:pin] self.range= @options[:range] self.clock= @options[:clock] @options.delete(:start) ? self.on : self.off end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/pi_piper/pwm.rb', line 9 def @options end |
#value ⇒ Object
Returns the value of attribute value.
9 10 11 |
# File 'lib/pi_piper/pwm.rb', line 9 def value @value end |
Instance Method Details
#off ⇒ Object Also known as: stop
Stop the Pwm signal
49 50 51 52 |
# File 'lib/pi_piper/pwm.rb', line 49 def off @on = false Platform.driver.pwm_mode(PWM_PIN[@options[:pin]][:channel], PWM_MODE.index([:mode]), 0) end |
#off? ⇒ Boolean
60 61 62 |
# File 'lib/pi_piper/pwm.rb', line 60 def off? not on? end |
#on ⇒ Object Also known as: start
Start the Pwm signal
41 42 43 44 |
# File 'lib/pi_piper/pwm.rb', line 41 def on @on = true Platform.driver.pwm_mode(PWM_PIN[@options[:pin]][:channel], PWM_MODE.index([:mode]), 1) end |
#on? ⇒ Boolean
56 57 58 |
# File 'lib/pi_piper/pwm.rb', line 56 def on? @on end |