class PinX
This is a base clase used by gems rpi_pwm, rpi_led_simulator, myfirmata-plugin-led, and simple_wiimote.
Constants
- HIGH
- LOW
Attributes
id[R]
Public Class Methods
new(id)
click to toggle source
# File lib/pinx.rb, line 22 def initialize(id) @id = id @on, @blinking = false, false end
Public Instance Methods
blink(seconds=0.5, duration: nil)
click to toggle source
# File lib/pinx.rb, line 64 def blink(seconds=0.5, duration: nil) self.stop if blinking? @blinking = true t2 = Time.now + duration if duration Thread.new do while @blinking do set_pin HIGH sleep seconds / 2.0 break if !@blinking sleep seconds / 2.0 break if !@blinking set_pin LOW sleep seconds / 2.0 break if !@blinking sleep seconds / 2.0 break if !@blinking self.off if duration and Time.now >= t2 end end end
Also aliased as: oscillate
blinking?()
click to toggle source
# File lib/pinx.rb, line 27 def blinking?() @blinking end
off(durationx=nil, duration: nil)
click to toggle source
# File lib/pinx.rb, line 42 def off(durationx=nil, duration: nil) set_pin LOW @on, @blinking = false, false duration ||= durationx @on_thread.exit if @on_thread @off_thread = Thread.new { (sleep duration; on()) } if duration end
off?()
click to toggle source
# File lib/pinx.rb, line 95 def off?() !@on end
on(durationx=nil, duration: nil)
click to toggle source
# File lib/pinx.rb, line 31 def on(durationx=nil, duration: nil) set_pin HIGH @on, @blinking = true, false duration ||= durationx @off_thread.exit if @off_thread @on_thread = Thread.new {(sleep duration; off()) } if duration end
on?()
click to toggle source
# File lib/pinx.rb, line 94 def on?() @on end
to_s()
click to toggle source
# File lib/pinx.rb, line 97 def to_s() @id end
Protected Instance Methods
set_pin(val)
click to toggle source
set val with 0 (off) or 1 (on)
# File lib/pinx.rb, line 105 def set_pin(val) @on = val end