alonewolfx2 wrote:Can you share your example code and which shift register?
Shift register is SN74HC595. I believe the HC is important, the datasheet says it can operate as low as 2V.
I don't have access to my home PC right now, but here's a snippet that I have access to.
The shiftOut without webserver is what you saw in the video. I have NOT successfully run shift register code WITH the webserver. I ran into odd errors and reboots. Maybe it is out of memory?!
EDIT: lua thinks my bit pattern string is a number so it puked when I did a string.sub() on it. tostring() around the bits fixed it.
-- I/O configuration --
dataPin=0
latchPin=1
clockPin=2
gpio.mode(dataPin,gpio.OUTPUT)
gpio.mode(latchPin,gpio.OUTPUT)
gpio.mode(clockPin,gpio.OUTPUT)
-- Initialize all to LOW --
gpio.write(dataPin,gpio.LOW)
gpio.write(latchPin,gpio.LOW)
gpio.write(clockPin,gpio.LOW)
function shiftOut(dataPin, clockPin, latchPin, bits)
gpio.write(latchPin,gpio.LOW) -- Don't reflect changes to LED (yet...)
for b=1,8 do
gpio.write(clockPin,gpio.LOW)
if (string.sub(bits, b,b) == "0") then
gpio.write(dataPin,gpio.HIGH)
else
gpio.write(dataPin,gpio.LOW)
end
gpio.write(clockPin,gpio.HIGH)
end
gpio.write(latchPin,gpio.HIGH) -- Transfer to LED
end
digits={"11111100", "01100000", "11011010", "11110010", "01100110", "10110110", "10111110", "11100000", "11111110", "11110110"}
frame=1
print(digits[frame])
bits = digits[8]
shiftOut(dataPin, clockPin, latchPin, bits)
-- LUA Webserver --
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
conn:on("receive",function(conn,payload)
forArduino = string.sub(payload, 6, 9) -- LUA substring is inclusive on both ends
--print(forArduino .. "\r\n")
reply = "Sent to Arduino: " .. forArduino
payloadLen = string.len(reply)
conn:send("HTTP/1.1 200 OK\r\n")
conn:send("Content-Length:" .. tostring(payloadLen) .. "\r\n")
conn:send("Connection:close\r\n\r\n")
conn:send(reply)
index = string.sub(payload,6,6)
digits={"11111100", "01100000", "11011010", "11110010", "01100110", "10110110", "10111110", "11100000", "11111110", "11110110"}
bitz = digits[index]
shiftOut(dataPin, clockPin, latchPin, bitz)
end)
conn:on("sent",function(conn)
conn:close()
end)
end)