Sha256: f95d4b04b3cbde49bb71c387154a7fcdb21e33782013387570e133cd379a82ae

Contents?: true

Size: 854 Bytes

Versions: 5

Compression:

Stored size: 854 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 => :device_info
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

5 entries across 5 versions & 1 rubygems

Version Path
artoo-arduino-1.4.2 examples/dc_motor_speed.rb
artoo-arduino-1.4.1 examples/dc_motor_speed.rb
artoo-arduino-1.4.0 examples/dc_motor_speed.rb
artoo-arduino-1.3.0 examples/dc_motor_speed.rb
artoo-arduino-1.2.0 examples/dc_motor_speed.rb