Skip to content

Commit

Permalink
add sinatra sample #8
Browse files Browse the repository at this point in the history
  • Loading branch information
shokai committed Oct 24, 2012
1 parent e5bfec6 commit 88a793f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
9 changes: 9 additions & 0 deletions samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,12 @@ Tweet Temperature
% gem install tw
% tw --user:add
% ruby tweet_temperature.rb


Sinatra Arduino
---------------

% gem install sinatra
% ruby sinatra_arduino.rb

=> http://localhost:4567
23 changes: 23 additions & 0 deletions samples/sinatra_arduino.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env ruby
$:.unshift File.expand_path '../lib', File.dirname(__FILE__)
require 'rubygems'
require 'sinatra'
require 'arduino_firmata'

arduino = ArduinoFirmata.connect

get '/' do
redirect './on'
end

get '/on' do
analog = arduino.analog_read(0)
arduino.digital_write 13, ArduinoFirmata::HIGH
"<p>analog : #{analog}</p><p><a href='./off'>off</a></p>"
end

get '/off' do
analog = arduino.analog_read(0)
arduino.digital_write 13, ArduinoFirmata::LOW
"<p>analog : #{analog}</p><p><a href='./on'>on</a></p>"
end

0 comments on commit 88a793f

Please sign in to comment.