class Frankenpins::LED
Attributes
default_duration[RW]
Public Class Methods
new(options={})
click to toggle source
# File lib/frankenpins/led.rb, line 14 def initialize(options={}) options[:direction] = :out @pin = Frankenpins::Pin.new(options) @using_pwm = false @pwm_max = 100 @is_on = false @brightness = 0 # TODO: Should be 0? @default_duration = nil @queue = TransitionQueue.new @queue.start! end
Public Instance Methods
brightness(value, opts={})
click to toggle source
# File lib/frankenpins/led.rb, line 41 def brightness(value, opts={}) duration = opts[:duration] || @default_duration if value != 100 || value != 0 || duration use_pwm! end props = { :pin => @pin } if duration props[:type] = :pwm props[:from] = @brightness props[:to] = value props[:duration] = duration elsif @using_pwm props[:type] = :pwm props[:value] = value else props[:type] = :digital props[:value] = false if @brightness == 0 props[:value] = true if @brightness == 100 end @queue.push(LEDTransition.new(props)) @brightness = value end
off(opts={})
click to toggle source
# File lib/frankenpins/led.rb, line 36 def off(opts={}) brightness(0, opts) @is_on = false end
on(opts={})
click to toggle source
# File lib/frankenpins/led.rb, line 31 def on(opts={}) brightness(100, opts) @is_on = true end
Private Instance Methods
use_pwm!()
click to toggle source
# File lib/frankenpins/led.rb, line 70 def use_pwm! if @using_pwm == false @pin.io.soft_pwm_create(@pin.wiring_pin, 0, @pwm_max) @using_pwm = true end end