Skip to content

Instantly share code, notes, and snippets.

@sankarcheppali
Created June 16, 2017 06:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sankarcheppali/57974b27996291566c844e92b8e2feff to your computer and use it in GitHub Desktop.
Save sankarcheppali/57974b27996291566c844e92b8e2feff to your computer and use it in GitHub Desktop.
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