Class: WallE::Pin
- Inherits:
-
Object
- Object
- WallE::Pin
- Defined in:
- lib/wall_e/pin.rb
Defined Under Namespace
Classes: UnsupportedModeError
Constant Summary collapse
- INPUT =
Internal: Fixnum byte for pin mode input.
0x00
- OUTPUT =
Internal: Fixnum byte for pin mode output.
0x01
- ANALOG =
Internal: Fixnum byte for pin mode analog.
0x02
- PWM =
Internal: Fixnum byte for pin mode pulse width modulation.
0x03
- SERVO =
Internal: Fixnum byte for pin mode servo.
0x04
- LOW =
0
- HIGH =
1
Instance Attribute Summary collapse
-
#number ⇒ Object
readonly
Public: Returns the Integer pin number.
Instance Method Summary collapse
-
#analog_write(value) ⇒ Object
(also: #servo_write)
Public: Write analog value to the pin.
-
#current_mode ⇒ Object
Public: Get the current mode.
-
#digital_write(value) ⇒ Object
Public: Write a digital value to the pin.
-
#initialize(number, board, mode = OUTPUT) ⇒ Pin
constructor
Public: Initialize a Pin.
-
#set_mode(mode) ⇒ Object
Public: Set the pin mode.
-
#value ⇒ Object
Public: Get the current value of the pin.
Constructor Details
#initialize(number, board, mode = OUTPUT) ⇒ Pin
Public: Initialize a Pin
number - the Integer pin number on the board. board - the WallE::Board this pin is on. mode - the Fixnum mode to set the pin to (default: OUTPUT).
27 28 29 30 31 32 |
# File 'lib/wall_e/pin.rb', line 27 def initialize(number, board, mode = OUTPUT) @number = number @board = board @onboard_pin = @board.pins[@number] set_mode(mode) end |
Instance Attribute Details
#number ⇒ Object (readonly)
Public: Returns the Integer pin number.
20 21 22 |
# File 'lib/wall_e/pin.rb', line 20 def number @number end |
Instance Method Details
#analog_write(value) ⇒ Object Also known as: servo_write
Public: Write analog value to the pin
value - an Integer value.
Returns nothing.
48 49 50 |
# File 'lib/wall_e/pin.rb', line 48 def analog_write(value) @board.analog_write(@number, value) end |
#current_mode ⇒ Object
Public: Get the current mode.
Returns Integer mode.
73 74 75 |
# File 'lib/wall_e/pin.rb', line 73 def current_mode @onboard_pin.mode end |
#digital_write(value) ⇒ Object
Public: Write a digital value to the pin.
value - an Integer value.
Returns nothing.
39 40 41 |
# File 'lib/wall_e/pin.rb', line 39 def digital_write(value) @board.digital_write(@number, value) end |
#set_mode(mode) ⇒ Object
Public: Set the pin mode.
mode - an Integer mode.
Returns nothing. Raises UnsupportedModeError if the pin does not support the mode.
65 66 67 68 |
# File 'lib/wall_e/pin.rb', line 65 def set_mode(mode) raise UnsupportedModeError unless @onboard_pin.supported_modes.include?(mode) @board.set_pin_mode(@number, mode) unless current_mode == mode end |
#value ⇒ Object
Public: Get the current value of the pin.
Returns Integer value.
80 81 82 |
# File 'lib/wall_e/pin.rb', line 80 def value @onboard_pin.value end |