Class: Mcp3008Pi
- Inherits:
-
Object
- Object
- Mcp3008Pi
- Defined in:
- lib/mcp3008pi.rb
Instance Method Summary collapse
-
#initialize(pin: 0, pins: [pin], clock: 18, dout: 23, din: 24, cs: 25) ⇒ Mcp3008Pi
constructor
A new instance of Mcp3008Pi.
- #read ⇒ Object
Constructor Details
#initialize(pin: 0, pins: [pin], clock: 18, dout: 23, din: 24, cs: 25) ⇒ Mcp3008Pi
Returns a new instance of Mcp3008Pi.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/mcp3008pi.rb', line 16 def initialize(pin: 0, pins: [pin], clock: 18, dout: 23, din: 24, cs: 25) @adc_pins = pins a = [clock, dout, din, cs] unexport_all a @clock = PiPiper::Pin.new :pin => clock, :direction => :out @adc_out = PiPiper::Pin.new :pin => dout @adc_in = PiPiper::Pin.new :pin => din, :direction => :out @cs = PiPiper::Pin.new :pin => cs, :direction => :out at_exit do # to avoid "Device or resource busy @ fptr_finalize - /sys/class/gpio/export" # we unexport the pins we used unexport_all a end end |
Instance Method Details
#read ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/mcp3008pi.rb', line 38 def read() a = @adc_pins.map {|pin| read_adc(pin, @clock, @adc_in, @adc_out, @cs) } return a.first if a.length == 1 return a end |