Drivers

Artoo has a extensible system for connecting to hardware devices.

Button


Simple interface that makes it possible to register clicks through physical input.

How To Connect

For Arduino:

require 'artoo'
connection :arduino, :adaptor => :firmata, :port => '127.0.0.1:8023'
device :button, :driver => :button, :pin => 2, :interval => 0.01

For Digispark:

require 'artoo'
connection :digispark, :adaptor => :littlewire, :vendor => 0x1781, :product => 0x0c9f
device :button, :driver => :button, :pin => 2, :interval => 0.01

How To Use

Pretty simple, when the connection and the driver have been setup (as explained above) you can call events on them as follows:

on button, :push    => proc { puts "button pressed!" }
on button, :release => proc { puts "button released!" }

Example using a button to turn a LED on and off.

require 'artoo'

connection :arduino, adaptor: :firmata, port: '127.0.0.1:8023'
device :led, driver: :led, pin: 13
device :button, driver: :button, pin: 2, interval: 0.01

work do
  puts "Press the button connected on pin #{ button.pin }..."

  on button, :push    => proc { led.on }
  on button, :release => proc { led.off }
end

Commands

is_pressed?

Returns true or false matching state of the button.

Params

no params

Returns

true or false

Events

start_driver

Starts the driver.

:push

This event gets triggered when the button changes state from released to pushed.

:release

This event gets triggered when the button changes state from pushed to released.

Circuit

Compatibility