where would I insert the delay code for Delay command?

HI,
long long story -----> short story,

I have this code, to turn on /off things at home remotely. modified.

my issue is that I need to have my switch 4 to turn on only for 1 second to open the garage door. I have written and have put down “delay(1000);” after the command but it doesnt work. I do not want it to be on all the time it wont work the the garage switch, it just needs to give a 1 or 0.5 second of impulse to open the door. what am I missing or doing wrong. I have erased the delay(1000); command in this one posted. Please help.

//*****************************************************

#include “SPI.h”
#include “Ethernet.h”
#include “WebServer.h”

static uint8_t mac = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
static uint8_t ip = {
192, 168, 1, 69 };

//**************************
// process post data here
//**************************
if (type == WebServer::POST)
{
bool repeat;
char name[16], value[16];

do
{
repeat = server.readPOSTparam(name, 16, value, 16);

if (strcmp(name, “Relay1”) == 0)
{
if (strcmp(value, “0”) == 0)
{
digitalWrite(2, HIGH);
}
else if (strcmp(value, “1”) == 0)
{
digitalWrite(2, LOW);
}
}

if (strcmp(name, “Relay2”) == 0)
{
if (strcmp(value, “0”) == 0)
{
digitalWrite(3, HIGH);
}
else if (strcmp(value, “1”) == 0)
{
digitalWrite(3, LOW);
}
}

if (strcmp(name, “Relay3”) == 0)
{
if (strcmp(value, “0”) == 0)
{
digitalWrite(4, HIGH);
}
else if (strcmp(value, “1”) == 0)
{
digitalWrite(4, LOW);
}
}

if (strcmp(name, “Relay4”) == 0)
{
if (strcmp(value, “0”) == 0)
{
digitalWrite(5, HIGH);
}
else if (strcmp(value, “1”) == 0)
{
digitalWrite(5, LOW);
}
}
}

while (repeat);

server.httpSeeOther(PREFIX);
return;
}

server.httpSuccess();

if (type == WebServer::GET)
{

P(messagestart) =
“Power Control Page”
“”

Power Control


“”;

P(messageend) =

LOGOUT


“”;

server.printP(messagestart);

if (Relay1active == 0)
{

if (digitalRead(2) == 0){
server.print("

");
server.print(R1text);
server.print(" - is On

");
}
else{
server.print("

");
server.print(R1text);
server.print("- is Off

");
}
}

if (Relay2active == 0)
{
if (digitalRead(3) == 0){
server.print("

");
server.print(R2text);
server.print(" - is On

");
}
else{
server.print("

");
server.print(R2text);
server.print("- is Off

");
}
}
if (Relay3active == 0)
{
if (digitalRead(4) == 0){
server.print("

");
server.print(R3text);
server.print(" - is On

");
}
else{
server.print("

");
server.print(R3text);
server.print("- is Off

");
}
}
if (Relay4active == 0)
{
if (digitalRead(5) == 0){
server.print("

");
server.print(R4text);
server.print(" - is On

");
}
else{
server.print("

");
server.print(R4text);
server.print("- is Off

");
}
}

server.printP(messageend);
}

}
else
{

server.httpUnauthorized();
}

}

void logoutCmd(WebServer &server, WebServer::ConnectionType type, char *, bool)
{

server.httpUnauthorized();

P(logoutMsg) = “

You have been logged out!

Goodbye

”;

server.printP(logoutMsg);

}

void setup()
{

if (Relay1active == 0){
pinMode(2, OUTPUT); //Set pin as output
if (Relay1state == 0){
digitalWrite(2, LOW);
}
else{
digitalWrite(2, HIGH);
}
}

if (Relay2active == 0){
pinMode(3, OUTPUT); //Set pin as output
if (Relay2state == 0){
digitalWrite(3, LOW);
}
else{
digitalWrite(3, HIGH);
}
}

if (Relay3active == 0){
pinMode(4, OUTPUT); //Set pin as output
if (Relay3state == 0){
digitalWrite(4, LOW);
}
else{
digitalWrite(4, HIGH);
}
}

if (Relay4active == 0){
pinMode(5, OUTPUT); //Set pin as output
if (Relay4state == 0){
digitalWrite(5, LOW);
}
else{
digitalWrite(5, HIGH);
}
}

Ethernet.begin(mac, ip);
webserver.setDefaultCommand(&defaultCmd);
webserver.addCommand(“index.html”, &defaultCmd);
webserver.addCommand(“logout.html”, &logoutCmd);
webserver.begin();

}

void loop()
{

webserver.processConnection();

}

Have you tried something like this?

 digitalWrite(4, LOW);
          delay(1000);
          digitalWrite(4,HIGH);
    
        }

yes I did.
but it does not respond. it stays on all the time. it's puzzling me.
I know it's something simple i'm missing!

int Relay3active = 0;   

...

    if (Relay3active == 0)

...

  if (Relay3active == 0){

When will it not be zero?

Please use code tags.

I'm sorry,
not following.

you mean it one of them should be 1 ?
then that one will always be ON ... no?

you mean it one of them should be 1 ?

He means that there is no point in testing the value if you know that it never changes.

Dump all that code. Write a simple sketch that turns the pin on, delay()s for one second, and then turns the pin off, and delay()s for another second. If the associated relay does not change state, then you have a hardware problem. If it does, then you have a software problem.

Which are we trying to solve?

NO it's not the hardware issue.
I have tried a simple code with delay which works fine.

I still cannot get it to work even if I have PIN not at 0 all the time.

not sure why delay command does not work!

When you are sufficiently frustrated it will be time to rewrite the code and put the different parts into different functions so you can see the logic separately from the actions. See planning and implementing a program.

...R

Your code does not compile, for example the code here should be inside a function:

#include "SPI.h"
#include "Ethernet.h"
#include "WebServer.h"

static uint8_t mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
static uint8_t ip[] = {
  192, 168, 1, 69 };


// <-------------------------- There should be a function here ---------

  //**************************
  // process post data here
  //**************************
  if (type == WebServer::POST)
  {
    bool repeat;
    char name[16], value[16];

What is the purpose of this?

    while (repeat);

What does this do?

  P(logoutMsg) = "<h1>You have been logged out!</h1> <p>Goodbye</p>";