-->
Page 1 of 1

Temporary Switch - Push switch type of functionality.

PostPosted: Sat May 02, 2015 2:59 pm
by bnvs
Okay Folks,

I am trying to make a run of the mill garage door opener. Nothing fancy. Just have a esp8266 SDK dev board that I do the programing on. Its has a relay built into it.

I want to figure out how I can turn the relay on only for say 500 milliseconds. Also I believe this can be though of as a "Normally Open Switch".

I know there is a much simple way then what I have right now. I just dont have the programming knowledge to figure out how to just insure the relay/switch is only ON for 500 milliseconds. Here is what I have done currently.

Can anyone show me a better way?

Code: Select alltimerId = 0
dly = 500 -- milliseconds
ledPin = 0
gpio.mode(ledPin,gpio.OUTPUT)
gpio.write(ledPin, 0)
ledState = 0
TimeOut = 0
print("Right now TimeOut = " .. TimeOut, ledState)
tmr.alarm( timerId, dly, 1, function()
if (TimeOut <= 1) then
TimeOut = TimeOut +1
ledState = 1 - ledState;
  gpio.write(ledPin, ledState)
print("Right now TimeOut = " .. TimeOut)
elseif(TimeOut > 1) then
gpio.write(ledPin, 0)
end
end)