Always keep the LEDs at a minimum
This commit is contained in:
		
							
								
								
									
										5
									
								
								main.lua
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								main.lua
									
									
									
									
									
								
							@@ -54,6 +54,9 @@ function displayTime()
 | 
			
		||||
     local words = display_timestat(time.hour, time.minute)
 | 
			
		||||
     if ((dim ~= nil) and (dim == "on")) then
 | 
			
		||||
        words.briPercent=briPercent
 | 
			
		||||
        if (words.briPercent ~= nil and words.briPercent < 3) then
 | 
			
		||||
          words.briPercent=3
 | 
			
		||||
        end
 | 
			
		||||
     else
 | 
			
		||||
        words.briPercent=nil
 | 
			
		||||
     end
 | 
			
		||||
@@ -164,7 +167,7 @@ function normalOperation()
 | 
			
		||||
    		end
 | 
			
		||||
        end)
 | 
			
		||||
        -- Start the time Thread
 | 
			
		||||
        tmr.alarm(1, 10000, 1 ,function()
 | 
			
		||||
        tmr.alarm(1, 5000, 1 ,function()
 | 
			
		||||
             displayTime()
 | 
			
		||||
             collectgarbage()
 | 
			
		||||
         end)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										10
									
								
								mqtt.lua
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								mqtt.lua
									
									
									
									
									
								
							@@ -9,13 +9,16 @@ function startMqtt()
 | 
			
		||||
        if (data == "ON") then
 | 
			
		||||
          briPercent=100
 | 
			
		||||
          m:publish(mqttPrefix .. "/clock", "ON", 0, 0)
 | 
			
		||||
          displayTime()
 | 
			
		||||
        elseif (data == "OFF") then
 | 
			
		||||
          briPercent=0
 | 
			
		||||
          m:publish(mqttPrefix .. "/clock", "OFF", 0, 0)
 | 
			
		||||
          displayTime()
 | 
			
		||||
        else
 | 
			
		||||
          if (tonumber(data) >= 0 and tonumber(data) <= 100) then
 | 
			
		||||
            briPercent=tonumber(data)
 | 
			
		||||
            m:publish(mqttPrefix .. "/clock", tostring(data), 0, 0)
 | 
			
		||||
            displayTime()
 | 
			
		||||
          end
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
@@ -37,8 +40,11 @@ end
 | 
			
		||||
if (mqttServer ~= nil and mqttPrefix ~= nil) then
 | 
			
		||||
    startMqtt()
 | 
			
		||||
    print "Started MQTT client"
 | 
			
		||||
 | 
			
		||||
    tmr.alarm(5, 30000, 1 ,function()
 | 
			
		||||
    oldBrightness=0
 | 
			
		||||
    tmr.alarm(5, 10000, 1 ,function()
 | 
			
		||||
        if (oldBrightness <> briPercent) then
 | 
			
		||||
         m:publish(mqttPrefix .. "/brightness", tostring(briPercent), 0, 0)
 | 
			
		||||
        end
 | 
			
		||||
        oldBrightness = briPercent
 | 
			
		||||
    end)
 | 
			
		||||
end
 | 
			
		||||
		Reference in New Issue
	
	Block a user