Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
The following function can push 16 bits of data to the shift registers (assuming two shifts registers cascaded)
serOut=2 --SER pin
clk=1 --shift register clock (SRCLK)
latch=3 -- Storage register clock (RCLK)
loadStatus=0 --use only 16 bits
gpio.mode(clk,gpio.OUTPUT)
gpio.mode(serOut,gpio.OUTPUT)
gpio.mode(latch,gpio.OUTPUT)
local function sendClk()
gpio.write(clk, gpio.HIGH)
tmr.delay(5)
gpio.write(clk, gpio.LOW)
end
local function sendLatch()
gpio.write(latch, gpio.HIGH)
tmr.delay(5)
gpio.write(latch, gpio.LOW)
end
local function serialOut(data)-- will shift out 16 bits,serially
for i=0,15 do
if bit.isclear(data,i) then gpio.write(serOut, gpio.LOW)
else gpio.write(serOut, gpio.HIGH) end
tmr.delay(5)
sendClk()
end
sendLatch()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment