write test to verify implementation
This commit is contained in:
parent
ad9747ba67
commit
640816fc38
30
test.rb
30
test.rb
|
@ -3,27 +3,37 @@
|
|||
# ruby: 1.9
|
||||
require 'serialport'
|
||||
|
||||
atmolight = SerialPort.open("/dev/ttyUSB0",{ baud: 38400, databits: 8, parity: SerialPort::NONE, stop_bit: 1, flow_control: SerialPort::NONE})
|
||||
screenlight = SerialPort.open("/dev/ttyUSB0",{ baud: 115200, databits: 8, parity: SerialPort::NONE, stop_bit: 1, flow_control: SerialPort::NONE})
|
||||
NB_LEDS = 60
|
||||
|
||||
# reset arduino
|
||||
atmolight.dtr = 1
|
||||
screenlight.dtr = 1
|
||||
sleep 0.5
|
||||
atmolight.dtr = 0
|
||||
screenlight.dtr = 0
|
||||
sleep 0.5
|
||||
atmolight.flush_output
|
||||
atmolight.flush_input
|
||||
atmolight.baud = 38400
|
||||
screenlight.flush_output
|
||||
screenlight.flush_input
|
||||
screenlight.baud = 115200
|
||||
|
||||
puts "waiting for welcome message"
|
||||
puts atmolight.gets
|
||||
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
|
||||
atmolight.write ([0xff,0x00,0x00,0x0f]+[white]*15).pack("C*") # set LED to red
|
||||
atmolight.flush_output
|
||||
#sleep 0.3
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue