Sha256: 5dbc9f4dee7f818742b32535209232694997b140bec1851ebd5610392aaec658

Contents?: true

Size: 696 Bytes

Versions: 1

Compression:

Stored size: 696 Bytes

Contents

require 'artoo'

leg1_pin = 7  # digital pin
leg2_pin = 4  # digital pin
speed_pin = 3 # PWM pin

speed = 0
forward = true

#connection :firmata, :adaptor => :firmata, :port => '/dev/tty*'
connection :firmata, :adaptor => :firmata, :port => '127.0.0.1:8023'
device :board, :driver => :board
device :motor, :driver => :motor, :pin => [leg1_pin, leg2_pin, speed_pin]

work do
  puts "Firmware name: #{board.firmware_name}"
  puts "Firmata version: #{board.version}"

  every(0.1)do
    forward ? motor.forward(speed) : motor.backward(speed)
    speed += 10
    if speed >= 255
      speed = 0
      forward = (not forward)
      sleep 1 # give the motor some time to stop inertia
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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