Class: SimpleRaspberryPi

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

Defined Under Namespace

Classes: Void

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x = []) ⇒ SimpleRaspberryPi

Returns a new instance of SimpleRaspberryPi.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/simple_raspberrypi.rb', line 21

def initialize(x=[])
  
  a = case x
  when Integer
    [x]    
  when Fixnum
    [x]
  when String
    [x]
  when Array
    x
  end
  
  @pins = a.map {|pin| RPiPinOut.new pin }
  
  def @pins.[](i)

    if i.to_i >= self.length then
      puts "RPi warning: RPiPinOut instance #{i.inspect} not found"
      Void.new
    else
      self.at(i)
    end 
  end    

end

Class Method Details

.[](i) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/simple_raspberrypi.rb', line 36

def @pins.[](i)

  if i.to_i >= self.length then
    puts "RPi warning: RPiPinOut instance #{i.inspect} not found"
    Void.new
  else
    self.at(i)
  end 
end

Instance Method Details

#pinObject



48
# File 'lib/simple_raspberrypi.rb', line 48

def pin()   @pins.first  end

#pinsObject



49
# File 'lib/simple_raspberrypi.rb', line 49

def pins()  @pins        end