firmata 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/firmata/board.rb +19 -0
- data/lib/firmata/version.rb +1 -1
- data/test/board_test.rb +19 -0
- metadata +2 -2
data/lib/firmata/board.rb
CHANGED
@@ -297,6 +297,25 @@ module Firmata
|
|
297
297
|
write(DIGITAL_MESSAGE | port, port_value & 0x7F, (port_value >> 7) & 0x7F)
|
298
298
|
end
|
299
299
|
|
300
|
+
# Public: Write an analog messege.
|
301
|
+
#
|
302
|
+
# pin - The Integer pin to write to.
|
303
|
+
# value - The Integer value to write to the pin between 0-255.
|
304
|
+
#
|
305
|
+
# Returns nothing.
|
306
|
+
def analog_write(pin, value)
|
307
|
+
@pins[pin].value = value
|
308
|
+
write(ANALOG_MESSAGE | pin, value & 0x7F, (value >> 7) & 0x7F)
|
309
|
+
end
|
310
|
+
|
311
|
+
# Public: Write to a servo.
|
312
|
+
#
|
313
|
+
# pin - The Integer pin to write to.
|
314
|
+
# degrees - The Integer degrees to move the servo.
|
315
|
+
#
|
316
|
+
# Returns nothing.
|
317
|
+
alias_method :servo_write, :analog_write
|
318
|
+
|
300
319
|
# Public: Ask the Arduino to sleep for a number of seconds.
|
301
320
|
#
|
302
321
|
# seconds - The Integer seconds to sleep for.
|
data/lib/firmata/version.rb
CHANGED
data/test/board_test.rb
CHANGED
@@ -210,7 +210,26 @@ class BoardTest < MiniTest::Unit::TestCase
|
|
210
210
|
|
211
211
|
board.digital_write(13, 1)
|
212
212
|
|
213
|
+
assert_equal 1, board.pins[13].value, "Pin value not set"
|
213
214
|
mock_sp.verify
|
214
215
|
end
|
215
216
|
|
217
|
+
def test_analog_write
|
218
|
+
mock_sp = mock_serial_port(233, 127, 1)
|
219
|
+
board = Firmata::Board.new(mock_sp)
|
220
|
+
|
221
|
+
8.times do |x|
|
222
|
+
board.pins[x + 8] = Firmata::Board::Pin.new([], 0, 250 + x, nil)
|
223
|
+
end
|
224
|
+
|
225
|
+
board.analog_write(9, 255)
|
226
|
+
|
227
|
+
assert_equal 255, board.pins[9].value
|
228
|
+
mock_sp.verify
|
229
|
+
end
|
230
|
+
|
231
|
+
def test_servo_write
|
232
|
+
board = Firmata::Board.new(FakeSerialPort.new)
|
233
|
+
assert board.respond_to? :servo_write
|
234
|
+
end
|
216
235
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: firmata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pry
|