class MyFirmataPluginLed
Public Class Methods
new(arduino, settings: {}, variables: {})
click to toggle source
# File lib/myfirmata-plugin-led.rb, line 27 def initialize(arduino, settings: {}, variables: {}) @arduino = arduino @settings, @variables = settings, variables x = settings[:pins] || settings[:pin] @pins = case x when Fixnum [x] when Integer [x] when String [x] when Array x end end
Public Instance Methods
on_led_message(message)
click to toggle source
# File lib/myfirmata-plugin-led.rb, line 46 def on_led_message(message) r = message.match(/(\d+)\s*(on|off|blink)\s*([\d\.]+)?(?:\s*duration\s)?([\d\.]+)?/) if r then index, state, seconds, raw_duration = r.captures duration = raw_duration ? raw_duration.to_f : nil a = case state when 'on' [:on, duration] when 'off' [:off] when 'blink' seconds = seconds ? seconds.to_f : 0.5 [:blink, seconds, duration: duration] end @led[index.to_i].send(*a) end end
start()
click to toggle source
# File lib/myfirmata-plugin-led.rb, line 71 def start() if @pins.any? then @led = @pins.map{|x| Led.new @arduino, x} end if @settings[:auto_test] then Thread.new {@led.each {|led| led.on; sleep 0.5; led.off; sleep 0.3} } end end
Also aliased as: on_start