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

User avatar
By ardhuru
#40605 I have a main routine, into which I embedded this;

Code: Select allfunction switchread()
    if (gpio.read(3)==0) then
    print("pressed!!")
    dofile("Mini_web.lua")
    else print("not!")
    end
--    print(gpio.read(3))
end
tmr.alarm(4,10,1,switchread) 


It does not work; the main program keeps running, but seems to do nothing when I press the switch.

BUT, if I run just the above segment, it works fine, calling the file 'Mini_web", and executing it.

I'm sure I'm doing something incredibly stupid here. Any idea what it could be?

Thanks!
User avatar
By xtal
#40639 LUA/nodemcu is a funny animal.....
off hand I see nothing wrong with the code, but apparently something is....

If I under stand the code you are executing the function every ???
I 'm thinking 10 us ,,, try 5000 ,,= 5 millisec I think.... you need to verify .....
you may want to stop the timer alarm when you load the other code ?
User avatar
By xtal
#40734 Looks like the time is 10 millisec should be good
on Arduino on my ESP-210 pin 3 == GPIO3 == Tx
Is this where your switch is ? pin mappings ? pin mode?
U may need gpio.mode(3,gpio.INPUT)

Try 4/5 gpio4 or gpio5 , keep in mind labels could be swapped 5=4 4=5

Here is an interesting snip I'm using..you might find a use for it..
Code: Select allSet do_next to the next function and after 100 ms it will be done .. its working fine
You can stop the timer alarm in any function .......
---------------  MAIN   ----------------------
do_next = c_station         -- was 250 ms
tmr.alarm( 0, 100, 1, function() do_next() end)       --@ 100 ms  do_next
-------------------------------------