As the title says... Chat on...

User avatar
By joefly888
#17437 Working on webserver with LED control. I only want the LED to be on for 2 seconds when requested.

So is there a simple wait, pause, delay that I can put in after the GPIO=high before I can set it to low again?
User avatar
By joefly888
#17464 hi , i incorporated your suggestion in this manner
Code: Select all        if(_GET.pin == "ON1")then
              gpio.write(led1, gpio.HIGH);
              ticker=millis();
              repeat
                 print ("hello");
                 -- do nothing as it is a delay
              until ( (millis() - ticker) > 2000 )
              gpio.write(led1, gpio.LOW);


if I declared the variable ticker at the beginning as
Code: Select allunsigned long ticker;


i get an error at boot with message of "lua: init.lua:1: '=' expected near 'long' "

if I removed the variable definition line, it boots fine, but when I get to the code of "ticker=millis()"
I get the panic message of "PANIC: unprotected error in call to Lua API (init.lua:29: attempt to call global 'millis' (a nil value))"

I am totally new to LUA so I am not sure if I am missing some syntax or something..
Last edited by joefly888 on Fri May 15, 2015 8:56 am, edited 1 time in total.
User avatar
By j0hncc
#17467 the nodemcu/lua way is to use Timer. No "arduino" loop or millis() stuff necessary

Code: Select all...
function turnOffLed()
    -- you figure out this part
end
...
--  Turn on Led and then turn it off in 2 seconds
turnOnLed()
tmr.alarm(  0, 2000, 1, turnOffLed )
...
... execution continues with your other code immediatly