arduino_firmata 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +2 -0
- data/README.rdoc +4 -0
- data/lib/arduino_firmata.rb +2 -1
- data/lib/arduino_firmata/arduino.rb +7 -1
- data/lib/arduino_firmata/event.rb +15 -0
- data/samples/analog_read_write.rb +2 -1
- data/samples/digital_read.rb +1 -1
- data/samples/led_blink.rb +1 -1
- data/samples/led_fade.rb +1 -1
- data/samples/on_changed.rb +18 -0
- data/samples/tweet_temperature.rb +1 -1
- metadata +4 -2
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
@@ -8,6 +8,7 @@ Rakefile
|
|
8
8
|
lib/arduino_firmata.rb
|
9
9
|
lib/arduino_firmata/arduino.rb
|
10
10
|
lib/arduino_firmata/const.rb
|
11
|
+
lib/arduino_firmata/event.rb
|
11
12
|
lib/arduino_firmata/main.rb
|
12
13
|
samples/README.md
|
13
14
|
samples/analog_read_write.rb
|
@@ -15,6 +16,7 @@ samples/block.rb
|
|
15
16
|
samples/digital_read.rb
|
16
17
|
samples/led_blink.rb
|
17
18
|
samples/led_fade.rb
|
19
|
+
samples/on_changed.rb
|
18
20
|
samples/tweet_temperature.rb
|
19
21
|
script/console
|
20
22
|
script/destroy
|
data/README.rdoc
CHANGED
data/lib/arduino_firmata.rb
CHANGED
@@ -18,6 +18,8 @@ module ArduinoFirmata
|
|
18
18
|
|
19
19
|
@version = nil
|
20
20
|
|
21
|
+
@on_analog_changed = []
|
22
|
+
|
21
23
|
@serial = SerialPort.new(serial_name, params[:bps], params[:bit], params[:stopbit], params[:parity])
|
22
24
|
@serial.read_timeout = 3
|
23
25
|
sleep 3
|
@@ -112,7 +114,11 @@ module ArduinoFirmata
|
|
112
114
|
when DIGITAL_MESSAGE
|
113
115
|
@digital_input_data[@multi_byte_channel] = (@stored_input_data[0] << 7) + @stored_input_data[1]
|
114
116
|
when ANALOG_MESSAGE
|
115
|
-
|
117
|
+
analog_value = (@stored_input_data[0] << 7) + @stored_input_data[1]
|
118
|
+
unless @analog_input_data[@multi_byte_channel] == analog_value
|
119
|
+
on_analog_changed @multi_byte_channel, analog_value
|
120
|
+
end
|
121
|
+
@analog_input_data[@multi_byte_channel] = analog_value
|
116
122
|
when REPORT_VERSION
|
117
123
|
@version = "#{@stored_input_data[1]}.#{@stored_input_data[0]}"
|
118
124
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module ArduinoFirmata
|
2
|
+
class Arduino
|
3
|
+
|
4
|
+
def on_analog_changed(pin, value=nil, &block)
|
5
|
+
if block_given?
|
6
|
+
@on_analog_changed.push(:pin => pin, :callback => block)
|
7
|
+
else
|
8
|
+
@on_analog_changed.each do |func|
|
9
|
+
func[:callback].call value if func[:pin] == pin
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#usr/bin/env ruby
|
2
|
-
require 'rubygems'
|
3
2
|
$:.unshift File.expand_path '../lib', File.dirname(__FILE__)
|
3
|
+
require 'rubygems'
|
4
4
|
require 'arduino_firmata'
|
5
5
|
|
6
6
|
arduino = ArduinoFirmata.connect ARGV.shift
|
@@ -11,3 +11,4 @@ loop do
|
|
11
11
|
arduino.analog_write 11, an/4
|
12
12
|
sleep 0.1
|
13
13
|
end
|
14
|
+
|
data/samples/digital_read.rb
CHANGED
data/samples/led_blink.rb
CHANGED
data/samples/led_fade.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
#usr/bin/env ruby
|
2
|
+
$:.unshift File.expand_path '../lib', File.dirname(__FILE__)
|
3
|
+
require 'rubygems'
|
4
|
+
require 'arduino_firmata'
|
5
|
+
|
6
|
+
arduino = ArduinoFirmata.connect ARGV.shift
|
7
|
+
|
8
|
+
arduino.on_analog_changed 0 do |value|
|
9
|
+
puts "analog pin 0 changed #{value}"
|
10
|
+
arduino.analog_write 11, value
|
11
|
+
end
|
12
|
+
|
13
|
+
led_stat = false
|
14
|
+
loop do
|
15
|
+
arduino.digital_write 13, led_stat
|
16
|
+
led_stat = !led_stat
|
17
|
+
sleep 1
|
18
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arduino_firmata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -101,6 +101,7 @@ files:
|
|
101
101
|
- lib/arduino_firmata.rb
|
102
102
|
- lib/arduino_firmata/arduino.rb
|
103
103
|
- lib/arduino_firmata/const.rb
|
104
|
+
- lib/arduino_firmata/event.rb
|
104
105
|
- lib/arduino_firmata/main.rb
|
105
106
|
- samples/README.md
|
106
107
|
- samples/analog_read_write.rb
|
@@ -108,6 +109,7 @@ files:
|
|
108
109
|
- samples/digital_read.rb
|
109
110
|
- samples/led_blink.rb
|
110
111
|
- samples/led_fade.rb
|
112
|
+
- samples/on_changed.rb
|
111
113
|
- samples/tweet_temperature.rb
|
112
114
|
- script/console
|
113
115
|
- script/destroy
|
@@ -132,7 +134,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
132
134
|
version: '0'
|
133
135
|
segments:
|
134
136
|
- 0
|
135
|
-
hash:
|
137
|
+
hash: -4444289282427680470
|
136
138
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
139
|
none: false
|
138
140
|
requirements:
|