Created
June 16, 2017 06:22
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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