Class: Led
- Inherits:
-
Object
- Object
- Led
- Defined in:
- lib/simple_wiimote.rb
Constant Summary collapse
- HIGH =
1- LOW =
0
Instance Attribute Summary collapse
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
- #blink(seconds = 0.5, duration: nil) ⇒ Object
-
#initialize(parent) ⇒ Led
constructor
A new instance of Led.
- #off ⇒ Object (also: #stop)
- #off? ⇒ Boolean
- #on(duration = nil) ⇒ Object
- #on? ⇒ Boolean
Constructor Details
Instance Attribute Details
#state ⇒ Object (readonly)
Returns the value of attribute state.
13 14 15 |
# File 'lib/simple_wiimote.rb', line 13 def state @state end |
Instance Method Details
#blink(seconds = 0.5, duration: nil) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/simple_wiimote.rb', line 33 def blink(seconds=0.5, duration: nil) @status = :blink t2 = Time.now + duration if duration Thread.new do while @status == :blink do @state = 1 (set_pin HIGH; sleep seconds; set_pin LOW; sleep seconds) self.off if duration and Time.now >= t2 end end end |
#off ⇒ Object Also known as: stop
26 27 28 29 30 31 |
# File 'lib/simple_wiimote.rb', line 26 def off() return if self.off? @state, @status = LOW, :off @parent.on_ledchange end |
#off? ⇒ Boolean
51 |
# File 'lib/simple_wiimote.rb', line 51 def off?() @status == :off end |
#on(duration = nil) ⇒ Object
20 21 22 23 24 |
# File 'lib/simple_wiimote.rb', line 20 def on(duration=nil) @state, @status = HIGH, :on @parent.on_ledchange (sleep duration; self.off) if duration end |
#on? ⇒ Boolean
50 |
# File 'lib/simple_wiimote.rb', line 50 def on?() @status == :on end |