screenlight/test.rb

40 lines
932 B
Ruby
Raw Normal View History

#!/usr/bin/env ruby
# encoding: utf-8
# ruby: 1.9
require 'serialport'
2015-07-18 20:15:18 +02:00
screenlight = SerialPort.open("/dev/ttyUSB0",{ baud: 115200, databits: 8, parity: SerialPort::NONE, stop_bit: 1, flow_control: SerialPort::NONE})
NB_LEDS = 60
# reset arduino
2015-07-18 20:15:18 +02:00
screenlight.dtr = 1
sleep 0.5
2015-07-18 20:15:18 +02:00
screenlight.dtr = 0
sleep 0.5
2015-07-18 20:15:18 +02:00
screenlight.flush_output
screenlight.flush_input
screenlight.baud = 115200
puts "waiting for welcome message"
2015-07-18 20:15:18 +02:00
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
2015-07-18 20:15:18 +02:00
screenlight.write ([0xff,0x00,0x00,3*NB_LEDS]+[white]*3*NB_LEDS).pack("C*") # set LED to red
screenlight.flush_output
sleep 0.02
2015-07-17 10:02:04 +02:00
white = (white+1)%256
puts "set white #{white} in #{Time.now-start} s"
end