-- M5450.lua John Longworth June 2017 -- Use ESP8266 to drive the M5450 IC clock = 1 -- Change these to whatever pins you are using data = 2 buffer = {} a = {0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1} gpio.mode(clock,gpio.OUTPUT) -- Set pins to outputs gpio.mode(data,gpio.OUTPUT) function writeBits() -- Write buffer to to M5450 buffer[35] = 1 -- needs to be 1 buffer[36] = 0 -- extra element to stop array going beyond its bounds for i = 0, 35 do gpio.write(clock,gpio.HIGH) gpio.write(data,buffer[i]) gpio.write(clock,gpio.LOW) end i = nil end function init() -- Make buffer for i = 0, 36 do buffer[i] = 0 end i = nil writeBits() end function random() -- Set random LEDs on or off tmr.alarm(0,1000,1,function() for i = 0, 34 do buffer[i] = node.random(0,1) end i = nil writeBits() end) end function chaser() -- 3 LED Chaser tmr.alarm(0,50,1,function() for i = 0, 34 do buffer[i] = 0 end i = nil count = count + 1 buffer[count - 1] = 1 buffer[count] = 1 buffer[count + 1] = 1 if count > 34 then count = 1 end i = nil writeBits() end) end function allOnOff() -- Turn all LEDs on and off tmr.alarm(0,500,1,function() for i = 0, 34 do buffer[i] = 1 end writeBits() i = nil end) tmr.alarm(1,1000,1,function() for i = 0, 34 do buffer[i] = 0 end writeBits() i = nil end) end function arrayFill() -- Use an array of pre defined values to set LEDS on or off for i = 0, 34 do buffer[i-1] = a[i] end writeBits() i = nil end function stop() tmr.stop(0) tmr.stop(1) arrayFill() end init() random() count = 1 tmr.alarm(2,10000,0,chaser) tmr.alarm(3,20000,0,allOnOff) tmr.alarm(4,30000,0,stop)