public
Description: A Ruby Arduino (RAD) project demonstration as a proof of concept Bar Monkey for the Orlando Ruby Users Group
Homepage:
Clone URL: git://github.com/mwilliams/barduino.git
barduino / barduino.rb
100644 42 lines (34 sloc) 0.835 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class Barduino < ArduinoSketch
 
  output_pin 5, :as => :pump_one
  output_pin 6, :as => :pump_two
  output_pin 13, :as => :led
  input_pin 0, :as => :photo_resistor
 
  serial_begin
 
  @serial_value = int
  @sensor = int
 
  def loop
    @sensor = analogRead(photo_resistor)
    if @sensor < 100
      digitalWrite led, ON
      if serial_available
        @serial_value = serial_read
        if @serial_value == '1'
          dispense pump_one
        end
        if @serial_value == '2'
          dispense pump_two
        end
      end
    else
      digitalWrite led, OFF
    end
  end
 
  def dispense(pump)
    # Hack for RubyToC to make it realize this dispense method
    # has a parameter to it (something along those lines).
    foo = pump + 0
    digitalWrite pump, ON
    delay 2000
    digitalWrite pump, OFF
  end
 
end