web controlled digital outputs

Hi all

Newbie Looking for some help with my sketch, i have ditigal outputs programed for web control the problem i have is the outputs don’t latch when triggered i only get a momentry pulse what iam looking for is when triggered to latch on until i send an off command, being very new to arduino i have used free code to start my sketch with a few modifications on my own
any help much appreciated

Z

Please see code below

////////////////////////////////////////////////////////////////////////
// LOAD LIBRARY
///////////////////////////////////////////////////////////////////////
#include <Ethernet.h>
#include <SPI.h>
boolean reading = false;

////////////////////////////////////////////////////////////////////////
//CONFIGURE
////////////////////////////////////////////////////////////////////////
byte mac = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
IPAddress ip(192, 192, 192,129); // ip address
EthernetServer server = EthernetServer(80); //port 80
char servername = “http://*************.no-ip.org”;
////////////////////////////////////////////////////////////////////////

void setup(){
Serial.begin(9600);
///////////////////////////////////////////////////////////////////////
//Pins 10,11,12 & 13 are used by the ethernet shield
//////////////////////////////////////////////////////////////////////
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);

Ethernet.begin(mac, ip);

server.begin();
Serial.println(Ethernet.localIP());
long time = 0;
long debounce = 200;
}

void loop(){
//////////////////////////////////////////////////////////////////////
// process request.
//////////////////////////////////////////////////////////////////////
checkForClient();

}

void checkForClient(){

EthernetClient client = server.available();

if (client) {

boolean currentLineIsBlank = true;
boolean sentHeader = false;

while (client.connected()) {
if (client.available()) {

if(!sentHeader){
//////////////////////////////////////////////////////////////////////
// send a standard http response header
//////////////////////////////////////////////////////////////////////
client.println(“HTTP/1.1 200 OK”);
client.println(“Content-Type: text/html”);
//**************************************************************
client.println(“Connection: close”);
client.println();
client.println("");
client.println("");
client.println("");
client.println(“Arduino Control”);
client.println("");
client.println("");
client.println(“

ARDUINO UNO PROJECT

”);
client.println(“

Home Automation Ver 1.0

”);
client.println(“

This program operates pin 2-9 on the adruino via the ethernet shield conformation of operation by Pin.

”);
//**************************************************************
client.println();
sentHeader = true;
}

char c = client.read();

if(reading && c == ’ ') reading = false;
if(c == ‘?’) reading = true; //found the ?, begin reading the info

if(reading){
Serial.print(c);

switch (c) {
case ‘2’:
//add code here to trigger on 2
triggerPin(2, client);
client.println(“

Garage Door

”);
break;
case ‘3’:
//add code here to trigger on 3
triggerPin(3, client);
client.println(“

Garage Lights

”);
break;
case ‘4’:
//add code here to trigger on 4
triggerPin(4, client);
client.println(“

Intruder Alarm

”);
break;
case ‘5’:
//add code here to trigger on 5
triggerPin(5, client);
client.println(“

Access Control

”);
break;
case ‘6’:
//add code here to trigger on 6
triggerPin(6, client);
client.println(“

Garage Heater

”);
break;
case ‘7’:
//add code here to trigger on 7
triggerPin(7, client);
client.println(“

NOT USED

”);
break;
case ‘8’:
//add code here to trigger on 8
triggerPin(8, client);
client.println(“

NOT USED

”);
break;
case ‘9’:
//add code here to trigger on 9
triggerPin(9, client);
client.println(“

NOT USED

”);
break;
}

}

if (c == ‘\n’ && currentLineIsBlank) break;

if (c == ‘\n’) {
currentLineIsBlank = true;
}else if (c != ‘\r’) {
currentLineIsBlank = false;
}

}
}
/////////////////////////////////////////////////////////////////////
// give the web browser time to receive the data
/////////////////////////////////////////////////////////////////////
delay(2);
////////////////////////////////////////////////////////////////////
// close the connection
////////////////////////////////////////////////////////////////////
client.stop(); // close the connection:

}

}
//************************************************************************
void triggerPin(int pin, EthernetClient client){
client.print("Turning on pin “);
client.println(pin);
client.print(”
");
/////////////////////////////////////////////////////////////////////////
digitalWrite(pin, HIGH);
delay(400);
digitalWrite(pin, LOW);
delay(400);
long time = 0;
long debounce = 1000;

}

Edit your post and insert code tags!

Here's the immediate issue:

digitalWrite(pin, HIGH);
delay(400);
digitalWrite(pin, LOW);

That second digital write is the problem. Naiively, you could just remove it but then you would need to add a different message to close it. Or you could keep a global boolean for each thing you're controlling to indicate whether its high or low and toggle it whenever you receive instruction to change it.

the outputs don't latch when triggered i only get a momentry pulse

Not surprising:

void triggerPin(int pin, EthernetClient client){
  client.print("Turning on pin ");
  client.println(pin);
  client.print("
");
/////////////////////////////////////////////////////////////////////////
  digitalWrite(pin, HIGH);
  delay(400);
  digitalWrite(pin, LOW);
  delay(400);
long time = 0;
long debounce = 1000;

}

The time and debounce variables are doing nothing, since they go out of scope immediately.

I'm guessing that you see a 400 millisecond pulse, right?

what iam looking for is when triggered to latch on until i send an off command

So, write the code that way.