-
Notifications
You must be signed in to change notification settings - Fork 3
/
barduino.rb
41 lines (34 loc) · 835 Bytes
/
barduino.rb
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
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