Created
January 11, 2015 04:43
-
-
Save spilth/ee0659457ac90468e281 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'arduino_firmata' | |
require 'l8' | |
l8 = L8::Smartlight.new "/dev/ttyACM0" | |
puts "Connected to L8" | |
l8.clear_matrix | |
l8.set_brightness(:low) | |
arduino = ArduinoFirmata.connect "/dev/ttyACM1" | |
puts "Connected to Arduino" | |
arduino.pin_mode 0, ArduinoFirmata::INPUT | |
puts "Starting main loop" | |
while true do | |
x = ((arduino.analog_read 0).to_f / 128.0).ceil - 1 | |
y = ((arduino.analog_read 1).to_f / 128.0).ceil - 1 | |
reset = arduino.digital_read 0 | |
if x < 0 | |
x = 0 | |
end | |
if y < 0 | |
y = 0 | |
end | |
puts "x: #{x}, y: #{y}" | |
l8.set_led(x, y, 15, 15, 15) | |
if reset | |
l8.clear_matrix | |
end | |
sleep 0.1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment