From 640816fc3821efeb20bc8f3727594038a54aa762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Sat, 18 Jul 2015 20:15:18 +0200 Subject: [PATCH] write test to verify implementation --- test.rb | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/test.rb b/test.rb index 890a3cd..a768708 100755 --- a/test.rb +++ b/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