Post your best Lua script examples here

User avatar
By Quindor
#6004
And can you explain how you chose the MOSFETs and what power requirements you are working with?

I was able to finish writing the part of my blog post detailing this little board and how to choose a correct MOSFET for it. Take a look here (It's about halfway down the post) and if you have any questions, let me know!
User avatar
By Quindor
#6101 I was able to write another 2 blog posts and basically get the 'basic' setup done. Following all the blog posts you should be able to create a neat little device which you can then control from the Domoticz Domotica software! :o

You can find the blog posts in the starting post!
User avatar
By VasilijHCN
#6144 Hi, first thank U for sharing.
I try to move this to esp-03 to control RGB LED strip, code works but wery incorrect - only one pin(LED1)controllable, other pins fail pwm (console show correct debug, but no reaction from other pwm pins)
Now all 3 channels working great, code corrected, using esp-03 pins 0, 14, 12 = pwm(3), pwm(5), pwm(6).
Now searching tcp app for android with slider, to control rgb strip easy.
Code: Select allpwm.setup(3, 1000, 005)
pwm.setup(5, 1000, 005)
pwm.setup(6, 1000, 005)
pwm.start(4)
pwm.start(5)
pwm.start(6)

LED1_current=005
LED1_target=005
LED2_current=005
LED2_target=005
LED3_current=005
LED3_target=005

Fadetime1=5000
Fadetime2=5000
Fadetime3=5000

Stepcounter1=0
PosStepcounter1=0
DimTimer1=0

Stepcounter2=0
PosStepcounter2=0
DimTimer2=0

Stepcounter3=0
PosStepcounter3=0
DimTimer3=0

wifi.setmode(wifi.STATION)
wifi.sta.config("SSID","PASSWORD")



srv=net.createServer(net.TCP)
srv:listen(43333,function(conn)
    conn:on("receive",function(conn,payload)
   
    print("Input:"..payload)
 
    if string.find(payload,"LED1") then
     LED1_target=tonumber(string.sub(payload, 13) )
     print("Received LED1 Target Value: "..LED1_target)

     Stepcounter1=(LED1_target)-(LED1_current)
     
     if (Stepcounter1) < 0 then
      PosStepcounter1=(Stepcounter1)*-1
      else PosStepcounter1=(Stepcounter1)
     end
     
     if (PosStepcounter1) == 0 then
      PosStepcounter1=(PosStepcounter1)+1
      else PosStepcounter1=(PosStepcounter1)
     end
         
     DimTimer1=(Fadetime1)/(PosStepcounter1)

     if (DimTimer1) == 0 then
      DimTimer1=(DimTimer1)+1
      else DimTimer1=(DimTimer1)
     end

      print (Fadetime1)
      print (Stepcounter1)
      print (PosStepcounter1)
      print (DimTimer1)
      print (LED1_current)
      print (LED1_target)


    tmr.alarm(0, (DimTimer1), 1, function()
     if LED1_current < LED1_target then
      LED1_current = (LED1_current + 1)
      pwm.setduty(3, LED1_current)
    elseif LED1_current > LED1_target then
      LED1_current = (LED1_current - 1)
      pwm.setduty(3, LED1_current)
    elseif LED1_current == LED1_target then tmr.stop(0)
     end end )
    end

    if string.find(payload,"LED2") then
        print("Received LED2 Target Value")
     LED2_target=tonumber(string.sub(payload, 13) )
     
     Stepcounter2=(LED2_target)-(LED2_current)
     
     if (Stepcounter2) < 0 then
      PosStepcounter2=(Stepcounter2)*-1
      else PosStepcounter2=(Stepcounter2)
     end
     
     if (PosStepcounter2) == 0 then
      PosStepcounter2=(PosStepcounter2)+1
      else PosStepcounter2=(PosStepcounter2)
     end
         
     DimTimer2=(Fadetime2)/(PosStepcounter2)

     if (DimTimer2) == 0 then
      DimTimer2=(DimTimer2)+1
      else DimTimer2=(DimTimer2)
     end

      print (Fadetime2)
      print (Stepcounter2)
      print (PosStepcounter2)
      print (DimTimer2)
      print (LED2_current)
      print (LED2_target)


    tmr.alarm(1, (DimTimer2), 1, function()
     if LED2_current < LED2_target then
      LED2_current = (LED2_current + 1)
      pwm.setduty(5, LED2_current)
    elseif LED2_current > LED2_target then
      LED2_current = (LED2_current - 1)
      pwm.setduty(5, LED2_current)
    elseif LED2_current == LED2_target then tmr.stop(1)
     end end )
    end
if string.find(payload,"LED3") then
     LED3_target=tonumber(string.sub(payload, 13) )
     print("Received LED3 Target Value: "..LED3_target)

     Stepcounter3=(LED3_target)-(LED3_current)
     
     if (Stepcounter3) < 0 then
      PosStepcounter3=(Stepcounter3)*-1
      else PosStepcounter3=(Stepcounter3)
     end
     
     if (PosStepcounter3) == 0 then
      PosStepcounter3=(PosStepcounter3)+1
      else PosStepcounter3=(PosStepcounter3)
     end
         
     DimTimer3=(Fadetime3)/(PosStepcounter3)

     if (DimTimer3) == 0 then
      DimTimer3=(DimTimer3)+1
      else DimTimer3=(DimTimer3)
     end

      print (Fadetime3)
      print (Stepcounter3)
      print (PosStepcounter3)
      print (DimTimer3)
      print (LED3_current)
      print (LED3_target)


    tmr.alarm(2, (DimTimer1), 1, function()
     if LED3_current < LED3_target then
      LED3_current = (LED3_current + 1)
      pwm.setduty(6, LED3_current)
    elseif LED3_current > LED3_target then
      LED3_current = (LED3_current - 1)
      pwm.setduty(6, LED3_current)
    elseif LED3_current == LED3_target then tmr.stop(2)
     end end )
    end
    end)
    end)

print ("Booted to QuinLED_ESP8266_V0.4")
Last edited by VasilijHCN on Fri Jan 02, 2015 6:23 pm, edited 1 time in total.