lib/frankenpins/pin.rb in frankenpins-0.2.1 vs lib/frankenpins/pin.rb in frankenpins-0.3.0

- old
+ new

@@ -12,11 +12,11 @@ INPUT = 0 PUD_OFF = 0 PUD_DOWN = 1 PUD_UP = 2 - attr_reader :pin, :last_value, :value, :direction, :invert + attr_reader :io, :pin, :wiring_pin, :last_value, :value, :direction, :invert def wiring_to_gpio(pin) @io.wpi_pin_to_gpio(pin) end @@ -105,9 +105,14 @@ # In short, you must call this method if you are curious about the current state of the pin. def read @last_value = @value val = File.read(value_file).to_i @value = invert ? (val ^ 1) : val + end + + def write(value) + value = value ? "1" : "0" + File.open(value_file, 'w') {|f| f.write(value) } if direction == :out end private def value_file "/sys/class/gpio/gpio#{pin}/value"