Class: GPIO::Pin
Instance Attribute Summary collapse
-
#direction ⇒ Object
Returns the value of attribute direction.
-
#name ⇒ Object
Returns the value of attribute name.
-
#number ⇒ Object
Returns the value of attribute number.
Instance Method Summary collapse
-
#as(dir = :out) ⇒ Object
set input or output gpio_num is the GPIO pin number, dir is the direction - either :out or :in.
-
#initialize(name, number) ⇒ Pin
constructor
A new instance of Pin.
-
#off ⇒ Object
send a low value to the pin.
-
#on ⇒ Object
send a high value to the pin.
-
#pwm(value) ⇒ Object
send a PWM (pulse width modulation) signal to the pin.
-
#read ⇒ Object
read from the pin.
-
#watch_for(value, &block) ⇒ Object
watch the pin for change and trigger the block over and over again.
-
#watch_once_for(value, &block) ⇒ Object
watch the pin for change and trigger the block once.
Constructor Details
#initialize(name, number) ⇒ Pin
Returns a new instance of Pin.
17 18 19 20 21 |
# File 'lib/ruby-gpio.rb', line 17 def initialize(name, number) init_mutex @name = name @number = number end |
Instance Attribute Details
#direction ⇒ Object
Returns the value of attribute direction.
15 16 17 |
# File 'lib/ruby-gpio.rb', line 15 def direction @direction end |
#name ⇒ Object
Returns the value of attribute name.
15 16 17 |
# File 'lib/ruby-gpio.rb', line 15 def name @name end |
#number ⇒ Object
Returns the value of attribute number.
15 16 17 |
# File 'lib/ruby-gpio.rb', line 15 def number @number end |
Instance Method Details
#as(dir = :out) ⇒ Object
set input or output gpio_num is the GPIO pin number, dir is the direction - either :out or :in
25 26 27 28 |
# File 'lib/ruby-gpio.rb', line 25 def as(dir=:out) @direction = dir.to_s GPIO.write "gpio#{@number}/direction", @direction end |
#off ⇒ Object
send a low value to the pin
36 37 38 |
# File 'lib/ruby-gpio.rb', line 36 def off GPIO.write "gpio#{@number}/value", "0" end |
#on ⇒ Object
send a high value to the pin
31 32 33 |
# File 'lib/ruby-gpio.rb', line 31 def on GPIO.write "gpio#{@number}/value", "1" end |
#pwm(value) ⇒ Object
send a PWM (pulse width modulation) signal to the pin
41 42 43 |
# File 'lib/ruby-gpio.rb', line 41 def pwm(value) GPIO.write "gpio#{@number}/value", value end |
#read ⇒ Object
read from the pin
46 47 48 |
# File 'lib/ruby-gpio.rb', line 46 def read GPIO.read @number end |
#watch_for(value, &block) ⇒ Object
watch the pin for change and trigger the block over and over again
62 63 64 65 66 67 68 |
# File 'lib/ruby-gpio.rb', line 62 def watch_for(value, &block) while true if read == value GPIO.instance_eval &block end end end |
#watch_once_for(value, &block) ⇒ Object
watch the pin for change and trigger the block once
51 52 53 54 55 56 57 58 59 |
# File 'lib/ruby-gpio.rb', line 51 def watch_once_for(value, &block) watching = true while watching if read == value GPIO.instance_eval &block watching = false end end end |