Sha256: 8d32e3717170df0debf457cb0d2b59e06691324e4053922441ee2adcec22b264
Contents?: true
Size: 964 Bytes
Versions: 2
Compression:
Stored size: 964 Bytes
Contents
require 'artoo' # For LED brightness: # Circuit and schematic here: http://arduino.cc/en/Tutorial/Fade # # For 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 :led, :driver => :led, :pin => 3 ai_pin = 0 work do puts "Reading sensor in analog pin #{ sensor.pin }" puts "Reading analog sensor intervals every => #{ sensor.interval }" every(0.25) do analog_read = sensor.analog_read(ai_pin) brightness_val = analog_read.to_pwm_reverse puts "Analog Read => #{ analog_read }" puts "brightness val => #{ brightness_val }" led.brightness(brightness_val) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
artoo-arduino-1.4.4 | examples/led_brightness_with_analog_input.rb |
artoo-arduino-1.4.3 | examples/led_brightness_with_analog_input.rb |