40 lines
932 B
Ruby
Executable File
40 lines
932 B
Ruby
Executable File
#!/usr/bin/env ruby
|
|
# encoding: utf-8
|
|
# ruby: 1.9
|
|
require 'serialport'
|
|
|
|
screenlight = SerialPort.open("/dev/ttyUSB0",{ baud: 115200, databits: 8, parity: SerialPort::NONE, stop_bit: 1, flow_control: SerialPort::NONE})
|
|
NB_LEDS = 60
|
|
|
|
# reset arduino
|
|
screenlight.dtr = 1
|
|
sleep 0.5
|
|
screenlight.dtr = 0
|
|
sleep 0.5
|
|
screenlight.flush_output
|
|
screenlight.flush_input
|
|
screenlight.baud = 115200
|
|
|
|
puts "waiting for welcome message"
|
|
puts screenlight.gets
|
|
|
|
puts "moving dot"
|
|
NB_LEDS.times do |led|
|
|
msg = [0xff,0x00,0x00,3*NB_LEDS]+[0x00]*3*NB_LEDS
|
|
msg[4+led*3] = 0xff
|
|
screenlight.write msg.pack("C*") # set LED to red
|
|
screenlight.flush_output
|
|
sleep 0.1
|
|
end
|
|
|
|
puts "white fading"
|
|
white = 0
|
|
while true do
|
|
start = Time.now
|
|
screenlight.write ([0xff,0x00,0x00,3*NB_LEDS]+[white]*3*NB_LEDS).pack("C*") # set LED to red
|
|
screenlight.flush_output
|
|
sleep 0.02
|
|
white = (white+1)%256
|
|
puts "set white #{white} in #{Time.now-start} s"
|
|
end
|