add atmolight tester
This commit is contained in:
parent
6b6589e93c
commit
cdd432302e
45
test.rb
45
test.rb
|
@ -3,7 +3,7 @@
|
|||
# ruby: 1.9
|
||||
require 'serialport'
|
||||
|
||||
atmolight = SerialPort.open("/dev/ttyUSB0",{ baud: 19200, databits: 8, parity: SerialPort::NONE, stop_bit: 1, flow_control: SerialPort::NONE})
|
||||
atmolight = SerialPort.open("/dev/ttyUSB0",{ baud: 38400, databits: 8, parity: SerialPort::NONE, stop_bit: 1, flow_control: SerialPort::NONE})
|
||||
|
||||
# reset arduino
|
||||
atmolight.dtr = 1
|
||||
|
@ -12,49 +12,18 @@ atmolight.dtr = 0
|
|||
sleep 0.5
|
||||
atmolight.flush_output
|
||||
atmolight.flush_input
|
||||
atmolight.baud = 19200
|
||||
atmolight.baud = 38400
|
||||
|
||||
puts "waiting for welcome message"
|
||||
puts atmolight.gets
|
||||
|
||||
puts "sending test commands"
|
||||
commands = [
|
||||
"\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # start bootloader
|
||||
"\x00\x87\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", # start application
|
||||
"\x1b\x1b\x1b\x1b\x1b\x1b\x1b\x1b\x1b\x1b\x1b\x1b\x1b\x1b\x1b\x00", # sync sequence
|
||||
"\x1b\x1b\x1b\x1b\x1b\x1b\x1b\x1b\x1b\x1b\x1b\x1b\x1b\x1b\x1b\x1b\x1b\x00", # too long sync sequence
|
||||
"\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" # unhandled command
|
||||
]
|
||||
commands.each do |command|
|
||||
sleep 0.5
|
||||
atmolight.write command
|
||||
atmolight.flush_output
|
||||
end
|
||||
|
||||
# test all LEDs with red
|
||||
puts "cycle LEDs"
|
||||
50.times do |i|
|
||||
atmolight.write [i,0x01,0x00,0x00,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00].pack("C*") # set LED to red
|
||||
atmolight.flush_output
|
||||
atmolight.write [0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00].pack("C*") # flush
|
||||
atmolight.flush_output
|
||||
sleep 0.25
|
||||
atmolight.write [i,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00].pack("C*") # switch off LED
|
||||
atmolight.flush_output
|
||||
end
|
||||
|
||||
# increase white
|
||||
|
||||
puts "white fading"
|
||||
atmolight.write "\x00\x87\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
||||
atmolight.flush_output
|
||||
sleep 0.5
|
||||
white = 0
|
||||
while true do
|
||||
start = Time.now
|
||||
51.times do |i|
|
||||
atmolight.write [i,0x01,0x00,0x00,white,white,white,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00].pack("C*") # set LED to red
|
||||
atmolight.flush_output
|
||||
end
|
||||
white = (white+10)%256
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue