screenlight/test.rb

30 lines
678 B
Ruby
Executable File

#!/usr/bin/env ruby
# encoding: utf-8
# ruby: 1.9
require 'serialport'
atmolight = SerialPort.open("/dev/ttyUSB0",{ baud: 38400, databits: 8, parity: SerialPort::NONE, stop_bit: 1, flow_control: SerialPort::NONE})
# reset arduino
atmolight.dtr = 1
sleep 0.5
atmolight.dtr = 0
sleep 0.5
atmolight.flush_output
atmolight.flush_input
atmolight.baud = 38400
puts "waiting for welcome message"
puts atmolight.gets
puts "white fading"
white = 0
while true do
start = Time.now
atmolight.write ([0xff,0x00,0x00,0x0f]+[white]*15).pack("C*") # set LED to red
atmolight.flush_output
#sleep 0.3
white = (white+1)%256
puts "set white #{white} in #{Time.now-start} s"
end