Sha256: f9353e3920fb005371b7a5546e80db5801864eeeb540768bf90fbd37b57d031a

Contents?: true

Size: 1014 Bytes

Versions: 2

Compression:

Stored size: 1014 Bytes

Contents

require 'artoo'
# For motor speed output:
# Circuit's breadboard layout here: http://learn.adafruit.com/adafruit-arduino-lesson-13-dc-motors/breadboard-layout
#
# For the analog input:
# Substitute the button with an analog sensor like a photoresistor and 
# change to the correct analog input, in this case pin A0.
# Circuit and schematic here: http://arduino.cc/en/tutorial/button

connection :firmata, :adaptor => :firmata, :port => '/dev/ttyACM0' #linux
#connection :firmata, :adaptor => :firmata, :port => '127.0.0.1:8023'
device :sensor, driver: :analog_sensor, pin: 0, interval: 0
device :motor, :driver => :motor, :speed_pin => 3 # Use a PWM pin

ai_pin = 0

work do

  puts "Reading sensor in analog pin #{ sensor.pin }"
  puts "Reading intervals every => #{ sensor.interval }"

  every(0.25) do
    analog_read = sensor.analog_read(ai_pin)
    motor_speed = analog_read.to_pwm
    puts "Analog Read => #{ analog_read }"
    puts "Motor Speed => #{ motor_speed }"
    motor.speed(motor_speed)
  end

end 

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
artoo-arduino-1.4.4 examples/motor_speed_with_analog_input.rb
artoo-arduino-1.4.3 examples/motor_speed_with_analog_input.rb