Class: DigitalEffector
Overview
DigitalEffector - effector/actuator with digitized control
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Effector
#model_name, #name
Constructor Details
#initialize(pins, state = :low) ⇒ DigitalEffector
Returns a new instance of DigitalEffector.
11
12
13
14
15
16
17
18
19
|
# File 'lib/digital_effector.rb', line 11
def initialize(pins, state=:low)
@states = {}
@pins = pins
@pins.each_value do |pin|
RPi::GPIO.setup pin, :as => :output, :initialize => state
@states[pin] = (state == :high)
end
@pin = pins.values[0]
end
|
Class Method Details
.off(pin = @pin) ⇒ Object
25
26
27
|
# File 'lib/digital_effector.rb', line 25
def self.off(pin=@pin)
RPi::GPIO.set_low pin
end
|
.on(pin = @pin) ⇒ Object
21
22
23
|
# File 'lib/digital_effector.rb', line 21
def self.on(pin=@pin)
RPi::GPIO.set_high pin
end
|
Instance Method Details
#off(pin = @pin) ⇒ Object
34
35
36
37
|
# File 'lib/digital_effector.rb', line 34
def off(pin=@pin)
BinaryEffector.off @pin
@states[pin] = false
end
|
#off?(pin = @pin) ⇒ Boolean
49
50
51
|
# File 'lib/digital_effector.rb', line 49
def off?(pin=@pin)
not on(pin)
end
|
#on(pin = @pin) ⇒ Object
29
30
31
32
|
# File 'lib/digital_effector.rb', line 29
def on(pin=@pin)
BinaryEffector.on @pin
@states[pin] = true
end
|
#on?(pin = @pin) ⇒ Boolean
39
40
41
42
43
44
45
46
47
|
# File 'lib/digital_effector.rb', line 39
def on?(pin=@pin)
state = nil
if pin.class.name == 'Fixnum' state = @states[pin]
elsif @pins[pin] state = @states[@pins[pin]]
end
state
end
|