README.md in arduino_firmata-0.2.0 vs README.md in arduino_firmata-0.2.1

- old
+ new

@@ -12,20 +12,25 @@ Requirements ------------ +* Ruby 1.8.7+ or 1.9.2+ +* Arduino (http://arduino.cc) + * testing with Arduino Duemillanove, UNO, Micro, Seeduino v2. * Arduino Standard Firmata v2.2 * Arduino IDE -> [File] -> [Examples] -> [Firmata] -> [StandardFirmata] -* Ruby 1.8.7+ -* Ruby 1.9.2+ Synopsis -------- -Setup +- https://github.com/shokai/arduino_firmata/tree/master/samples + +### Setup + +Connect ```ruby require 'arduino_firmata' arduino = ArduinoFirmata.connect # use default arduino arduino = ArduinoFirmata.connect '/dev/tty.usb-device-name' @@ -35,20 +40,34 @@ Board Version ```ruby puts "firmata version #{arduino.version}" ``` +Close +```ruby +arduino.close +``` + + +### I/O + Digital Write ```ruby arduino.digital_write 13, true arduino.digital_write 13, false ``` Digital Read ```ruby arduino.pin_mode 7, ArduinoFirmata::INPUT puts arduino.digital_read 7 # => true/false + +arduino.on :digital_read do |pin, status| + if pin == 7 + puts "digital pin #{pin} changed : #{status}" + end +end ``` Analog Write (PWM) ```ruby 0.upto(255) do |i| @@ -61,11 +80,11 @@ ```ruby puts arduino.analog_read 0 # => 0 ~ 1023 arduino.on :analog_read 0 do |pin, value| if pin == 0 - puts "analog pin #{pin} changed #{value}" + puts "analog pin #{pin} changed : #{value}" end end ``` Servo Motor @@ -75,42 +94,42 @@ arduino.servo_write 11, angle sleep 1 end ``` -Close -```ruby -arduino.close -``` -Block -```ruby -ArduinoFirmata.connect do - puts "firmata version #{version}" +### Sysex - 30.times do - an = analog_read 0 - analog_write 11, an - sleep 0.01 - end -end -``` +- http://firmata.org/wiki/V2.1ProtocolDetails#Sysex_Message_Format +- https://github.com/shokai/arduino_firmata/tree/master/samples/sysex -Send Sysex Command +Send ```ruby -arduino.sysex 0x01, [13, 5, 2] +arduino.sysex 0x01, [13, 5, 2] # command, data_array ``` -Regist Sysex Command Event +Regist Receive Event ```ruby arduino.on :sysex do |command, data| puts "command : #{command}" puts "data : #{data.inspect}" end ``` -see samples https://github.com/shokai/arduino_firmata/tree/master/samples +### Block Style + +```ruby +ArduinoFirmata.connect do + puts "firmata version #{version}" + + 30.times do + an = analog_read 0 + analog_write 11, an + sleep 0.01 + end +end +``` Test ---- % gem install bundler \ No newline at end of file