arduino 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/arduino.gemspec +1 -1
  2. data/example_blink.rb +6 -4
  3. data/lib/arduino.rb +32 -13
  4. metadata +2 -2
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "arduino"
6
- s.version = "0.3.2"
6
+ s.version = "0.3.3"
7
7
  s.date = %q{2011-01-01}
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Akash Manohar"]
@@ -1,15 +1,17 @@
1
1
  require "./lib/arduino"
2
2
 
3
3
  #specify the port as an argument
4
- myBoard = Arduino.new('/dev/ttyUSB0')
4
+ board = Arduino.new('/dev/ttyUSB0')
5
5
 
6
6
  #declare output pins
7
- myBoard.output(13)
7
+ board.output(13)
8
8
 
9
9
  #perform operations
10
10
  10.times do
11
- myBoard.setHigh(13)
11
+ board.setHigh(13)
12
+ puts "High" if board.getState(13)
12
13
  sleep(1)
13
- myBoard.setLow(13)
14
+ board.setLow(13)
15
+ puts "Low" if !board.getState(13)
14
16
  sleep(1)
15
17
  end
@@ -18,6 +18,7 @@ class Arduino
18
18
  @serial.sync
19
19
  @port = port
20
20
  @outputPins = []
21
+ @pinStates = {}
21
22
  end
22
23
 
23
24
  # Print information about connected board
@@ -37,27 +38,51 @@ class Arduino
37
38
  else
38
39
  raise ArgumentError, "Arguments must be a list of pin numbers"
39
40
  end
40
- end
41
-
42
- # Get state of a digital pin. Returns true if high and false if low.
43
- def getState(pin)
44
- sendData('2')
45
- sendPin(pin)
46
- return formatPinState(getData())
41
+ return pinList
47
42
  end
48
43
 
49
44
  # Set a pin state to low
50
45
  def setLow(pin)
46
+ saveState(pin, false)
51
47
  sendData('0')
52
48
  sendPin(pin)
53
49
  end
54
50
 
51
+ def isLow?(pin)
52
+ if !getState(pin)
53
+ return true
54
+ else
55
+ return false
56
+ end
57
+ end
58
+
55
59
  # Set a pin state to high
56
60
  def setHigh(pin)
61
+ saveState(pin, true)
57
62
  sendData('1')
58
63
  sendPin(pin)
59
64
  end
60
65
 
66
+ def isHigh?(pin)
67
+ if getState(pin)
68
+ return true
69
+ else
70
+ return false
71
+ end
72
+ end
73
+
74
+ def saveState(pin, state)
75
+ @pinStates[pin.to_s] = state
76
+ end
77
+
78
+ # Get state of a digital pin. Returns true if high and false if low.
79
+ def getState(pin)
80
+ if @pinStates.key?(pin.to_s)
81
+ return @pinStates[pin.to_s]
82
+ end
83
+ return false
84
+ end
85
+
61
86
  # Write to an analog pin
62
87
  def analogWrite(pin, value)
63
88
  sendData('3')
@@ -109,10 +134,4 @@ class Arduino
109
134
  cleanData = @serial.readlines()
110
135
  cleanData = cleanData.join("").gsub("\n","").gsub("\r","")
111
136
  end
112
-
113
- def formatPinState(pinValue)
114
- return true if pinValue=="1"
115
- return false #if pinValue=="0"
116
- end
117
-
118
137
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 2
9
- version: 0.3.2
8
+ - 3
9
+ version: 0.3.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Akash Manohar