Date post: | 14-May-2015 |
Category: |
Technology |
Upload: | austinbv |
View: | 338 times |
Download: | 1 times |
Austin Vance
arduinothe ruby way
Monday, November 5, 12
Monday, November 5, 12
/austinbv
@austinbv
Monday, November 5, 12
arduino.. what now?
Monday, November 5, 12
arduino.. what now?
Monday, November 5, 12
arduino.. what now?
Monday, November 5, 12
arduino.. what now?
Monday, November 5, 12
arduino.. what now?
Monday, November 5, 12
arduino.. what now?
Monday, November 5, 12
arduino.. what now?
Monday, November 5, 12
arduino.. what now?
Monday, November 5, 12
arduino.. what now?
Monday, November 5, 12
arduino.. what now?
Monday, November 5, 12
what can you do with it?
Monday, November 5, 12
can’twhat can you do with it?
Monday, November 5, 12
can’tWhat can you do with it?
Monday, November 5, 12
can’tWhat can you do with it?
Monday, November 5, 12
can’tWhat can you do with it?
Monday, November 5, 12
can’tWhat can you do with it?
Monday, November 5, 12
can’tWhat can you do with it?
Monday, November 5, 12
the ide
Monday, November 5, 12
the ide
Monday, November 5, 12
the ide
Monday, November 5, 12
Burn code
to the
arduino
Monday, November 5, 12
• standalone• isolated• small
Monday, November 5, 12
developed by Greg Borenstein
Ruby Arduino Development
RAD
Monday, November 5, 12
Ruby
class Blinky < ArduinoSketch output_pin 13, :as => :led def loop blink led, 100 endend
Monday, November 5, 12
Ruby compiles to C#include <WProgram.h>#include <SoftwareSerial.h>void loop();void setup();int main();int led();void loop();int _led = 13;int led() { return _led;}void setup() { pinMode(13, OUTPUT);}void blink(int pin, int ms) { digitalWrite( pin, HIGH ); delay( ms ); digitalWrite( pin, LOW ); delay( ms );}int main() { init(); setup(); for( ;; ) { loop(); } return 0;}void loop() { blink(led(), 100);}
class Blinky < ArduinoSketch output_pin 13, :as => :led def loop blink led, 100 endend
Monday, November 5, 12
debuggingoutdated
Monday, November 5, 12
Talk with
the
Arduino
Monday, November 5, 12
• standalone• isolated• small
Monday, November 5, 12
• standalone• isolated• small
Monday, November 5, 12
• standalone• isolated• small
Monday, November 5, 12
• standalone• isolated• small
Monday, November 5, 12
• standalone• small
Monday, November 5, 12
✓standalone• small
Monday, November 5, 12
✓standalone✓small
Monday, November 5, 12
isolation is not import
Monday, November 5, 12
Monday, November 5, 12
async
Monday, November 5, 12
ecto/duinoThe Arduino listens for low-level
signals over a serial port, while we abstract all of the logic on the Node
side.“ ”
Monday, November 5, 12
complex logic
and problems
Monday, November 5, 12
small C++ library
complex logic
and problems
Monday, November 5, 12
message passing
Monday, November 5, 12
?Monday, November 5, 12
dino
introducing!
Monday, November 5, 12
Goals• fully tested• easy to extend• great documentation• zero startup time• fun
Monday, November 5, 12
beginning developmentand use what’s there
thank you duino && node.js
Monday, November 5, 12
Asynchronous in a synchronous world
Monday, November 5, 12
Event Machine
Monday, November 5, 12
EM.run do board = RubyDuino::Board.new board.callback do board.send_message '0013001' do EM::add_periodic_timer 0.5 do board.send_message “0013#{blink}” end end endend
Monday, November 5, 12
Monday, November 5, 12
roll our own• developer control• specific to the gem• zero dependencies
Monday, November 5, 12
How did it turn out?
Monday, November 5, 12
class Board
Monday, November 5, 12
==Monday, November 5, 12
♥Monday, November 5, 12
class TxRx
Monday, November 5, 12
Monday, November 5, 12
finds the arduino
Monday, November 5, 12
injected into the board
Monday, November 5, 12
oh the possibilities
Monday, November 5, 12
don’t panic
Monday, November 5, 12
module Components
Monday, November 5, 12
class < BaseComponent
Monday, November 5, 12
class Led
Monday, November 5, 12
def initialize(options={}) super(options) set_pin_mode(:out) digital_write(Board::LOW) end
def on digital_write(Board::HIGH) end
def off digital_write(Board::LOW) end
Monday, November 5, 12
board = Board.new(Dino::TxRx.new)led = Led.new(pin: 2, board: board) led.onsleep 2led.off
Monday, November 5, 12
class Button
Monday, November 5, 12
def initialize(options={}) self.board.add_digital_hardware(self) self.board.start_readend#...def update(data) case data when UP button_up when DOWN button_down endend
Monday, November 5, 12
Monday, November 5, 12
down = proc { led.on }up = proc { led.off } button.down(down)button.up(up)
Monday, November 5, 12
class Sensor
Monday, November 5, 12
def initialize(options={}) @data_callbacks = [] @board.add_analog_hardware(self) @board.start_readend def update(data) @data_callbacks.each do |callback| callback.call(data) endend
Monday, November 5, 12
on_data = proc { |data| puts data} sensor .when_data_received(on_data)
Monday, November 5, 12
class Stepper
Monday, November 5, 12
def step_cc digital_write(Board::HIGH, pins[:dir]) digital_write(Board::HIGH, pins[:step]) digital_write(Board::LOW, pins[:step])end def step_cw digital_write(Board::LOW, pins[:dir]) digital_write(Board::HIGH, pins[:step]) digital_write(Board::LOW, pins[:step])end
Monday, November 5, 12
1600.times do stepper.step_cc sleep 0.001end
1600.times do stepper.step_cw sleep 0.001end
Monday, November 5, 12
and many more
Monday, November 5, 12
and many more
Monday, November 5, 12
and many more
Monday, November 5, 12
and many more
Monday, November 5, 12
and many more
Monday, November 5, 12
Lets see it in action
Monday, November 5, 12
use it with any ruby script
reporter = proc { if system('./build') green.on && red.off else green.off && red.on end} button.down(reporter)
Monday, November 5, 12
Monday, November 5, 12
initializer
Monday, November 5, 12
sinatraboard = Board.new(Dino::TxRx.new)cannon = Led.new(pin: 2, board: board)
put ‘/launch‘ docannon.on
end
Monday, November 5, 12
/austinbv/dino
@austinbv
Thank You!
Monday, November 5, 12