Class: PiWire::OutputPin

Inherits:
Pin
  • Object
show all
Defined in:
lib/pi_wire/output_pin.rb,
ext/pi_wire/pi_wire_output_pin.c

Instance Attribute Summary

Attributes inherited from Pin

#number

Instance Method Summary collapse

Constructor Details

#initialize(number) ⇒ OutputPin

Returns a new instance of OutputPin.



3
4
5
6
# File 'lib/pi_wire/output_pin.rb', line 3

def initialize(number)
  @number = number
  self.mode = PiWire::OUTPUT_MODE
end

Instance Method Details

#high!Object



20
21
22
# File 'lib/pi_wire/output_pin.rb', line 20

def high!
  write PiWire::HIGH
end

#high?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/pi_wire/output_pin.rb', line 12

def high?
  read == PiWire::HIGH
end

#low!Object



16
17
18
# File 'lib/pi_wire/output_pin.rb', line 16

def low!
  write PiWire::LOW
end

#low?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/pi_wire/output_pin.rb', line 8

def low?
  read == PiWire::LOW
end

#readObject



3
4
5
6
# File 'ext/pi_wire/pi_wire_output_pin.c', line 3

static VALUE read(VALUE self) {
  int pin_value = digitalRead(pin_number(self));
  return INT2FIX(pin_value);
}

#toggle!Object



24
25
26
# File 'lib/pi_wire/output_pin.rb', line 24

def toggle!
  low? ? high! : low!
end

#write(rb_int) ⇒ Object Also known as: <<



8
9
10
11
# File 'ext/pi_wire/pi_wire_output_pin.c', line 8

static VALUE write(VALUE self, VALUE rb_int) {
  digitalWrite(pin_number(self), NUM2INT(rb_int));
  return Qtrue;
}