diff --git a/displayword.lua b/displayword.lua index 8ec0fd6..fab35a3 100644 --- a/displayword.lua +++ b/displayword.lua @@ -1,7 +1,6 @@ -- Module displaying of the words -function generateLEDs(words) +function generateLEDs(words, color) - color=string.char(0,0,50) white=string.char(0,0,0) buf=color -- line 1---------------------------------------------- @@ -153,4 +152,4 @@ function generateLEDs(words) buf= buf .. white:rep(1) end return buf -end \ No newline at end of file +end diff --git a/main.lua b/main.lua index 1fcb7a2..a16ef53 100644 --- a/main.lua +++ b/main.lua @@ -4,11 +4,20 @@ dofile("wordclock.lua") dofile("displayword.lua") timezoneoffset=1 +ledPin=4 +color=string.char(0,0,250) +connect_counter=0 -- Wait to be connect to the WiFi access point. -tmr.alarm(0, 100, 1, function() +tmr.alarm(0, 500, 1, function() + connect_counter=connect_counter+1 if wifi.sta.status() ~= 5 then print("Connecting to AP...") + if (connect_counter % 2 == 0) then + ws2812.write(ledPin, string.char(255,0,0):rep(114)) + else + ws2812.write(ledPin, string.char(0,0,0):rep(114)) + end else tmr.stop(0) print('IP: ',wifi.sta.getip()) @@ -22,7 +31,16 @@ tmr.alarm(0, 100, 1, function() print('failed!') end ) - + end + -- when no wifi available, open an accesspoint and ask the user + if (connect_counter == 300) then -- 300 is 30 sec in 100ms cycle + tmr.stop(0) + wifi.setmode(wifi.SOFTAP) + wifi.ap.config({ssid='clock',pwd='clock'}) + print("Waiting in access point >clock< for Clients") + print("Please visit 192.168.4.1") + + dofile("webserver.lua") end end) @@ -33,9 +51,9 @@ tmr.alarm(1, 5000, 1 ,function() print("Local time : " .. time.year .. "-" .. time.month .. "-" .. time.day .. " " .. time.hour .. ":" .. time.minute .. ":" .. time.second) words = display_timestat(time.hour, time.minute) - ledBuf = generateLEDs(words) + ledBuf = generateLEDs(words, color) -- Write the buffer to the LEDs - ws2812.write(4, ledBuf) + ws2812.write(ledPin, ledBuf) for key,value in pairs(words) do if (value > 0) then