Commit a02afeb1 authored by Micha's avatar Micha

...

parent 8efbab40
require 'socket'
class UDPSender
@host = ''
@port = 0
@socket = nil
def initialize(host, port)
@host = host
@port = port
@socket = UDPSocket.new
end
def udpSend(stuff)
@socket.send(stuff, 0, @host, @port)
end
def flush()
flushBytes = [255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255]
udpSend(flushBytes.pack('C*'))
sleep(15.0/1000)
end
def setLED(ledState)
udpSend(ledState.pack('C*'))
sleep(1.0/1000)
end
def setLamp(index, led1, led2, led3, led4, led5, led6)
#calculate led index base
base = index * 6
led1.insert(0, base)
led2.insert(0, base+1)
led3.insert(0, base+2)
led4.insert(0, base+3)
led5.insert(0, base+4)
led6.insert(0, base+5)
sendArray = led1.push(*led2).push(*led3).push(*led4).push(*led5).push(*led6)
udpSend(sendArray.pack('C*'))
sleep(1.0/1000)
end
def switchOff()
for i in 0..12
setLamp(i, [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0])
end
flush()
end
def switchOffLamp(lampIndex)
baseIndex = lampIndex*6
for i in 0..5
setLED([baseIndex+i, 0, 0, 0])
end
flush()
end
def setSingleLED(lampIndex, ledIndex, red, green, blue)
for i in 0..5
if i == ledIndex
setLED([lampIndex*6 + i, red, green, blue])
else
setLED([lampIndex*6 + i, 0, 0, 0])
end
end
end
def rotateRight(lampIndex, red, green, blue)
baseIndex = lampIndex*6
for i in 0..5
setSingleLED(lampIndex, i, red, green, blue)
flush()
end
end
def rotateLeft(lampIndex, red, green, blue)
baseIndex = lampIndex*6
for i in 0..5
setSingleLED(lampIndex, 5-i, red, green, blue)
flush()
end
end
def disco(lampIndex, red, green, blue)
baseIndex = lampIndex*6
for i in 0..5
setLED([baseIndex+i, red, green, blue])
flush()
end
for i in 0..5
setLED([baseIndex+i, 0, 0, 0])
flush()
end
end
def discoAllRandom()
for i in 0..5
for j in 0..12
setLED([j*6 + i, rand(255), rand(255), rand(255)])
end
flush()
sleep(1.0/500)
end
for i in 0..5
for j in 0..12
setLED([j*6 + i, 0, 0, 0])
end
flush()
sleep(1.0/500)
end
end
def rotateRight(red, green, blue)
for i in 0..5
for j in 0..12
setSingleLED(j, i, red, green, blue)
end
flush()
end
end
def rotateAllLeft(red, green, blue)
for i in 0..5
for j in 0..12
setSingleLED(j, 5-i, red, green, blue)
end
flush()
end
end
end
ip = '10.1.25.31'
port = 8888
sender = UDPSender.new(ip, port)
sender.flush()
sender.switchOff()
for i in 0..255
for j in (0..12).step(2)
sender.setLamp(j, [0,i,255-i], [0,i,255-i], [0,i,255-i], [0,i,255-i], [0,i,255-i], [0,i,255-i])
sender.setLamp(j+1, [0,255-i,i], [0,255-i,i], [0,255-i,i], [0,255-i,i], [0,255-i,i], [0,255-i,i])
end
sender.flush()
end
sender.switchOff()
for j in (0..12)
sender.setLamp(j, [255,255,255], [255,255,255], [255,255,255], [255,255,255], [255,255,255], [255,255,255])
end
sender.flush()
sender.switchOff()
for j in (0..12)
sender.setLamp(j, [0,0,255], [0,0,255], [0,0,255], [0,0,255], [0,0,255], [0,0,255])
end
sender.flush()
sender.switchOff()
for j in (0..12)
sender.setLamp(j, [0,255,0], [0,255,0], [0,255,0], [0,255,0], [0,255,0], [0,255,0])
end
sender.flush()
sender.switchOff()
for j in (0..12)
sender.setLamp(j, [255,0,0], [255,0,0], [255,0,0], [255,0,0], [255,0,0], [255,0,0])
end
sender.flush()
for i in 0..8
sender.switchOff()
for j in (0..12)
sender.setLamp(j, [255,255,255], [255,255,255], [255,255,255], [255,255,255], [255,255,255], [255,255,255])
end
sender.flush()
end
sender.switchOff()
for i in 0..12
sender.setLamp(i, [255, 0, 0], [255, 0, 0], [255, 0, 0], [255, 0, 0], [255, 0, 0], [255, 0, 0])
sender.flush
sleep(1.0/5.0)
end
for i in 0..12
sender.setLamp(i, [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0])
sender.flush
sleep(1.0/5.0)
end
for i in 0..12
sender.setLamp(12-i, [255, 0, 0], [255, 0, 0], [255, 0, 0], [255, 0, 0], [255, 0, 0], [255, 0, 0])
sender.flush
sleep(1.0/5.0)
end
for i in 0..12
sender.setLamp(12-i, [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0])
sender.flush
sleep(1.0/5.0)
end
for k in 0..5
for i in 0..6
sender.setLamp(12-i, [255, 51*k, 51*k], [255, 51*k, 51*k], [255, 51*k, 51*k], [255, 51*k, 51*k], [255, 51*k, 51*k], [255, 51*k, 51*k])
sender.setLamp(i, [255, 51*k, 51*k], [255, 51*k, 51*k], [255, 51*k, 51*k], [255, 51*k, 51*k], [255, 51*k, 51*k], [255, 51*k, 51*k])
sender.flush
sleep(1.0/(5.0+k))
end
sender.switchOff()
end
for i in 0..8
sender.switchOff()
for j in (0..12)
sender.setLamp(j, [255,255,255], [255,255,255], [255,255,255], [255,255,255], [255,255,255], [255,255,255])
end
sender.flush()
end
for i in 0..30
sender.discoAllRandom()
end
#for i in 0..255
# for j in (0..12).step(2)
# sender.setLamp(j+1, [0,i,255-i], [0,i,255-i], [0,i,255-i], [0,i,255-i], [0,i,255-i], [0,i,255-i])
# sender.setLamp(j, [0,255-i,i], [0,255-i,i], [0,255-i,i], [0,255-i,i], [0,255-i,i], [0,255-i,i])
# end
# sender.flush()
#end
#end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment