A Simple First Script - nodemcu/nodemcu-devkit GitHub Wiki
Toggle the on-board LED at a period of two seconds
Here's a simple first script for testing out your NodeMCU devkit, taken from Rui Santos' Getting Started with the ESPlorer:
lighton=0
pin=4
gpio.mode(pin,gpio.OUTPUT)
tmr.alarm(1,2000,1,function()
if lighton==0 then
lighton=1
gpio.write(pin,gpio.HIGH)
else
lighton=0
gpio.write(pin,gpio.LOW)
end
end)