Skip to content

Instantly share code, notes, and snippets.

@tecteun
Created May 12, 2016 20:54
Show Gist options
  • Save tecteun/0b47bc2e9c2a74a021a048543c2301ff to your computer and use it in GitHub Desktop.
Save tecteun/0b47bc2e9c2a74a021a048543c2301ff to your computer and use it in GitHub Desktop.
Qifei 4-bit LED Digital Tube Module, NodeMCU ESP8266
--Cheap tube module, code for ESP8266 NodeMCU
--depends on ntp.lua
--https://gist.github.com/lucsmall/66d9b6539df7a0daa569
--http://www.esp8266.com/viewtopic.php?p=12733
--http://forum.43oh.com/topic/8596-4-digit-display-from-qifei/
--Qifei 4-bit LED Digital Tube Module, aka 74HC595
--
--D7 -> DIO
--D5 -> sclk
--D4 -> rclk
latch_pin = 4
chars = {
0xC0, --//0
0xF9, --//1
0xA4, --//2
0xB0, --//3
0x99, --//4
0x92, --//5
0x82, --//6
0xF8, --//7
0x80, --//8
0x90, --//9
0x88, --//A
0x83, --//b
0xC6, --//C
0xA1, --//d
0x86, --//E
0x8E --//F
};
ntpobj = loadfile("ntp.lua")()
print(ntpobj)
ntpobj:run(3,1,1800,nil)
tmr.alarm(4,500,1,function()
time = ntpobj:show_time()
digit1 = chars[tonumber(string.sub(time, 1, 1))+1]
digit2 = chars[tonumber(string.sub(time, 2, 2))+1]
digit3 = chars[tonumber(string.sub(time, 4, 4))+1]
digit4 = chars[tonumber(string.sub(time, 5, 5))+1]
end)
time = nil
digit1 = chars[2]
digit2 = chars[4]
digit3 = chars[4]
digit4 = chars[8]
gpio.mode(latch_pin, gpio.OUTPUT)
gpio.write(latch_pin, gpio.LOW)
result = spi.setup(1, spi.MASTER, spi.CPOL_HIGH, spi.CPHA_LOW, spi.DATABITS_8, 0)
tmr.alarm(1,8,1,function() -- min delay for tmr.alarm == 8us
gpio.write(latch_pin, gpio.LOW)
spi.send(1, digit1)
spi.send(1, tonumber("00001000", 2) )
gpio.write(latch_pin, gpio.HIGH)
gpio.write(latch_pin, gpio.LOW)
spi.send(1, digit2)
--spi.send(1, bit.band(tonumber("10000110", 2), tonumber("01111111", 2)))
spi.send(1, tonumber("000000100", 2) )
gpio.write(latch_pin, gpio.HIGH)
gpio.write(latch_pin, gpio.LOW)
spi.send(1, digit3)
--spi.send(1, bit.band(tonumber("10000110", 2), tonumber("01111111", 2)))
spi.send(1, tonumber("00000010", 2) )
gpio.write(latch_pin, gpio.HIGH)
gpio.write(latch_pin, gpio.LOW)
spi.send(1, digit4)
--spi.send(1, bit.band(tonumber("10000110", 2), tonumber("01111111", 2)))
spi.send(1, tonumber("00000001", 2) )
gpio.write(latch_pin, gpio.HIGH)
--clear
gpio.write(latch_pin, gpio.LOW)
spi.send(1, 0x00 )
gpio.write(latch_pin, gpio.HIGH)
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment