arduino_firmata 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 0.2.1 2013-01-13
2
+
3
+ * add digital_read event - Arduino::on(:digital_read, pin, status)
4
+
1
5
  === 0.2.0 2013-01-12
2
6
 
3
7
  * Sysex Command support
data/README.md CHANGED
@@ -14,16 +14,21 @@ Install
14
14
  Requirements
15
15
  ------------
16
16
 
17
+ * Ruby 1.8.7+ or 1.9.2+
18
+ * Arduino (http://arduino.cc)
19
+ * testing with Arduino Duemillanove, UNO, Micro, Seeduino v2.
17
20
  * Arduino Standard Firmata v2.2
18
21
  * Arduino IDE -> [File] -> [Examples] -> [Firmata] -> [StandardFirmata]
19
- * Ruby 1.8.7+
20
- * Ruby 1.9.2+
21
22
 
22
23
 
23
24
  Synopsis
24
25
  --------
25
26
 
26
- Setup
27
+ - https://github.com/shokai/arduino_firmata/tree/master/samples
28
+
29
+ ### Setup
30
+
31
+ Connect
27
32
  ```ruby
28
33
  require 'arduino_firmata'
29
34
 
@@ -37,6 +42,14 @@ Board Version
37
42
  puts "firmata version #{arduino.version}"
38
43
  ```
39
44
 
45
+ Close
46
+ ```ruby
47
+ arduino.close
48
+ ```
49
+
50
+
51
+ ### I/O
52
+
40
53
  Digital Write
41
54
  ```ruby
42
55
  arduino.digital_write 13, true
@@ -47,6 +60,12 @@ Digital Read
47
60
  ```ruby
48
61
  arduino.pin_mode 7, ArduinoFirmata::INPUT
49
62
  puts arduino.digital_read 7 # => true/false
63
+
64
+ arduino.on :digital_read do |pin, status|
65
+ if pin == 7
66
+ puts "digital pin #{pin} changed : #{status}"
67
+ end
68
+ end
50
69
  ```
51
70
 
52
71
  Analog Write (PWM)
@@ -63,7 +82,7 @@ puts arduino.analog_read 0 # => 0 ~ 1023
63
82
 
64
83
  arduino.on :analog_read 0 do |pin, value|
65
84
  if pin == 0
66
- puts "analog pin #{pin} changed #{value}"
85
+ puts "analog pin #{pin} changed : #{value}"
67
86
  end
68
87
  end
69
88
  ```
@@ -77,30 +96,18 @@ loop do
77
96
  end
78
97
  ```
79
98
 
80
- Close
81
- ```ruby
82
- arduino.close
83
- ```
84
99
 
85
- Block
86
- ```ruby
87
- ArduinoFirmata.connect do
88
- puts "firmata version #{version}"
100
+ ### Sysex
89
101
 
90
- 30.times do
91
- an = analog_read 0
92
- analog_write 11, an
93
- sleep 0.01
94
- end
95
- end
96
- ```
102
+ - http://firmata.org/wiki/V2.1ProtocolDetails#Sysex_Message_Format
103
+ - https://github.com/shokai/arduino_firmata/tree/master/samples/sysex
97
104
 
98
- Send Sysex Command
105
+ Send
99
106
  ```ruby
100
- arduino.sysex 0x01, [13, 5, 2]
107
+ arduino.sysex 0x01, [13, 5, 2] # command, data_array
101
108
  ```
102
109
 
103
- Regist Sysex Command Event
110
+ Regist Receive Event
104
111
  ```ruby
105
112
  arduino.on :sysex do |command, data|
106
113
  puts "command : #{command}"
@@ -108,8 +115,20 @@ arduino.on :sysex do |command, data|
108
115
  end
109
116
  ```
110
117
 
111
- see samples https://github.com/shokai/arduino_firmata/tree/master/samples
112
118
 
119
+ ### Block Style
120
+
121
+ ```ruby
122
+ ArduinoFirmata.connect do
123
+ puts "firmata version #{version}"
124
+
125
+ 30.times do
126
+ an = analog_read 0
127
+ analog_write 11, an
128
+ sleep 0.01
129
+ end
130
+ end
131
+ ```
113
132
 
114
133
  Test
115
134
  ----
@@ -188,7 +188,14 @@ module ArduinoFirmata
188
188
  if @execute_multi_byte_command != 0 and @wait_for_data == 0
189
189
  case @execute_multi_byte_command
190
190
  when DIGITAL_MESSAGE
191
+ digital_inputs = @digital_input_data.clone
191
192
  @digital_input_data[@multi_byte_channel] = (@stored_input_data[0] << 7) + @stored_input_data[1]
193
+ 0.upto(15).each do |i|
194
+ current = digital_read i
195
+ if current != ((digital_inputs[i >> 3] >> (i & 0x07)) & 0x01 > 0)
196
+ emit :digital_read, i, current
197
+ end
198
+ end
192
199
  when ANALOG_MESSAGE
193
200
  analog_value = (@stored_input_data[0] << 7) + @stored_input_data[1]
194
201
  unless @analog_input_data[@multi_byte_channel] == analog_value
@@ -1,4 +1,4 @@
1
1
 
2
2
  module ArduinoFirmata
3
- VERSION = '0.2.0'
3
+ VERSION = '0.2.1'
4
4
  end
data/samples/README.md CHANGED
@@ -7,6 +7,7 @@ Digital/Analog IO
7
7
  - led_blink.rb
8
8
  - led_fade.rb
9
9
  - on_analog_read.rb
10
+ - on_digital_read.rb
10
11
  - servo.rb
11
12
 
12
13
 
@@ -5,10 +5,10 @@ require 'arduino_firmata'
5
5
 
6
6
  arduino = ArduinoFirmata.connect ARGV.shift
7
7
 
8
- arduino.pin_mode 7, ArduinoFirmata::INPUT
8
+ arduino.pin_mode 2, ArduinoFirmata::INPUT
9
9
 
10
10
  loop do
11
- if arduino.digital_read 7
11
+ if arduino.digital_read 2
12
12
  puts "on"
13
13
  arduino.digital_write 13, true
14
14
  else
@@ -0,0 +1,20 @@
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
+ arduino.pin_mode 2, ArduinoFirmata::INPUT
8
+
9
+ arduino.on :digital_read do |pin, status|
10
+ if pin == 2
11
+ puts "digital pin #{pin} changed : #{status}"
12
+ end
13
+ end
14
+
15
+ led_stat = false
16
+ loop do
17
+ arduino.digital_write 13, led_stat
18
+ led_stat = !led_stat
19
+ sleep 1
20
+ 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.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -87,6 +87,7 @@ files:
87
87
  - samples/led_blink.rb
88
88
  - samples/led_fade.rb
89
89
  - samples/on_analog_read.rb
90
+ - samples/on_digital_read.rb
90
91
  - samples/servo.rb
91
92
  - samples/sinatra_arduino.rb
92
93
  - samples/sysex/README.md