Skip to content

Instantly share code, notes, and snippets.

@arkarkark
Created July 19, 2021 00:22
Show Gist options
  • Save arkarkark/2cfd35b8fc94d3b2ae3e219186feef00 to your computer and use it in GitHub Desktop.
Save arkarkark/2cfd35b8fc94d3b2ae3e219186feef00 to your computer and use it in GitHub Desktop.
a small lua file to make an ESP01 turn on a relay for 20 minutes then off for 20 minutes and repeat.
-- luacheck: globals gpio tmr
gpio.mode(3, gpio.OUTPUT) -- GPIO0
gpio.write(3, gpio.LOW)
-- gpio.mode(4, gpio.OUTPUT) -- GPIO2
local TWENTY_MINUTES = 20 * 60 * 1000
local THIRTY_MINUTES = 30 * 60 * 1000
local SIXTY_MINUTES = 60 * 60 * 1000
local on
local function off()
print("off")
gpio.write(3, gpio.HIGH)
local t = tmr.create()
t:register(TWENTY_MINUTES, tmr.ALARM_SINGLE, on)
t:start()
end
on = function ()
print("on")
gpio.write(3, gpio.LOW)
local t = tmr.create()
t:register(TWENTY_MINUTES, tmr.ALARM_SINGLE, off)
t:start()
end
print("starting")
on()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment