Skip to content

Instantly share code, notes, and snippets.

@spilth
Created January 11, 2015 04:43
Show Gist options
  • Save spilth/ee0659457ac90468e281 to your computer and use it in GitHub Desktop.
Save spilth/ee0659457ac90468e281 to your computer and use it in GitHub Desktop.
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