Class: Beaglebone::ShiftRegister

Inherits:
Object
  • Object
show all
Defined in:
lib/beaglebone/shiftregister.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(latch_pin, clock_pin, data_pin, lsb = nil) ⇒ ShiftRegister

Create a shiftregister object based on 3 GPIO pins

Examples:

shiftregister = ShiftRegister.new(:P9_11, :P9_12, :P9_13)

Parameters:

  • latch_pin

    should be a symbol representing the header pin, i.e. :P9_12

  • clock_pin

    should be a symbol representing the header pin, i.e. :P9_13

  • data_pin

    should be a symbol representing the header pin, i.e. :P9_14

  • lsb (defaults to: nil)

    optional, send least significant bit first if set



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/beaglebone/shiftregister.rb', line 15

def initialize(latch_pin, clock_pin, data_pin, lsb=nil)

  @latch_pin = latch_pin
  @clock_pin = clock_pin
  @data_pin  = data_pin
  @lsb       = lsb

  GPIO::pin_mode(@latch_pin, :OUT)
  GPIO::pin_mode(@clock_pin, :OUT)
  GPIO::pin_mode(@data_pin, :OUT)
end

Instance Method Details

#shift_out(data, lsb = nil) ⇒ Object

Send data to shift register

Examples:

shiftregister = ShiftRegister.new(:P9_11, :P9_12, :P9_13)
shiftregister.shift_out(255)

Parameters:

  • data

    Integer value to write to the shift register

  • lsb (defaults to: nil)

    optional, send least significant bit first if set



35
36
37
# File 'lib/beaglebone/shiftregister.rb', line 35

def shift_out(data, lsb=nil)
  GPIO::shift_out(@latch_pin, @clock_pin, @data_pin, data, lsb || @lsb)
end