class GPIO::Pin

Attributes

direction[RW]
name[RW]
number[RW]

Public Class Methods

new(name, number) click to toggle source
# File lib/ruby-gpio.rb, line 17
def initialize(name, number)
  init_mutex
  @name = name
  @number = number
end

Public Instance Methods

as(dir=:out) click to toggle source

set input or output gpio_num is the GPIO pin number, dir is the direction - either :out or :in

# File lib/ruby-gpio.rb, line 25
def as(dir=:out)
  @direction = dir.to_s
  GPIO.write "gpio#{@number}/direction", @direction
end
off() click to toggle source

send a low value to the pin

# File lib/ruby-gpio.rb, line 36
def off
  GPIO.write "gpio#{@number}/value", "0"
end
on() click to toggle source

send a high value to the pin

# File lib/ruby-gpio.rb, line 31
def on
  GPIO.write "gpio#{@number}/value", "1"
end
pwm(value) click to toggle source

send a PWM (pulse width modulation) signal to the pin

# File lib/ruby-gpio.rb, line 41
def pwm(value)
  GPIO.write "gpio#{@number}/value", value
end
read() click to toggle source

read from the pin

# File lib/ruby-gpio.rb, line 46
def read
  GPIO.read @number
end
watch_for(value, &block) click to toggle source

watch the pin for change and trigger the block over and over again

# 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) click to toggle source

watch the pin for change and trigger the block once

# 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