Sha256: 36f2ab431f3764790e556e350161d567378265608d08659109a9c78bd730c8c0

Contents?: true

Size: 848 Bytes

Versions: 1

Compression:

Stored size: 848 Bytes

Contents

require 'artoo'

#Circuit's breadboard layout here: http://learn.adafruit.com/adafruit-arduino-lesson-13-dc-motors/breadboard-layout

#connection :firmata, :adaptor => :firmata, :port => '/dev/tty*'
connection :firmata, :adaptor => :firmata, :port => '127.0.0.1:4567'
device :board, :driver => :board
device :motor, :driver => :motor, :speed_pin => 3 # Use a PWM pin

work do
  puts "Firmware name: #{board.firmware_name}"
  puts "Firmata version: #{board.version}"
  puts "Stopping motor..."
  motor.min # same as 'motor.stop' or 'motor.speed(0)'
  sleep 3
  puts "Setting to maximum speed..."
  motor.max # same as 'motor.start'
  sleep 3

  speed = 0
  step = 50

  every 3.seconds do
    motor.speed(speed)
    puts "Current speed: #{motor.current_speed}"
    speed += step
    if [0, 250].include?(speed)
      step = -step
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
artoo-arduino-1.1.0 examples/firmata_dc_motor_speed.rb