i thought I HAD mentioned this was for my grannies garden that she struggles to water now!!! smiley-wink
ha , ha , ha. XD
Here is the code that i have attempted to change, as you will see its not any good!!!
First of all, I assumed you realized that the code posted in my last post was just a snippet from the sketch I uploaded previously (garagesensor). I know that sketch works and others have used it as an example to create countdown or up timers. Secondly, reread my last post. I specifically said to rename the variables to something relevant to your application. Which you have not done. I'm trying to help you but I require your cooperation. If I tell you to do something, do it. If you cannot follow instructions, do it yourself. I am not being rude. I am laying down the rules. This code you are asking for is not a single line. Everything has to occur in steps. The first step is define your variables. You should know that. You cannot write code until you have done that. Your application does not involve a backlit lcd so you couldn't possibly run that code and tell me if it works or not. Telling me your modication to a sketch that controls a device you don't even possess is "no good" is absurd. There is no code in their for controlling a relay and this line:
if(readString.indexOf("?relay4off") >0)
doesn't belong here.
//==============================================
blpinStatus : this is variable used to indicate whether or not the user has pressed a pushbutton to turn on the backlight (which would start the 10 second countdown) You don't have a pushbutton so you need to tell your program that you are starting the timer. Simply turning on the relay does not provide any input to the timer code. You need a boolean (or integer) variable that denotes the starting of of the countdown timer . ie:
int starttimer=0;
static unsigned long blTime; //You don't have a backlight so it makes no sense to have a variable named blTime. Obviously this needs
to be changed to either relay_time or relay4_time. You decide.
static boolean blOn; // This is boolean that denotes the state of the backlight but unlike the blStatus, it does not indicate a switch
press, it indicates the status and of the backlight , not of any switch pin. Just to be clear, if you want to know the state of the backlight you could use some kind of hardware feedback, like a light sensor or measure the voltage on the current limiting resistor for the backlight. But since there was no need for that when this sketch was written, the status was monitored by using a boolean flag that was set when the backlight was turned on and cleared when it was turned off. You need to do the same thing for all four relays, which means the name of this flag should be relay4_on, or relay_on. You decide.
if (blpinStatus == LOW) // can't discuss this line because you haven't changed the variable name yet.
{
delay(20); // Debounce (you don't have a switch so there is nothing to debounce
blOn = true; // can't discuss this line because you haven't changed the variable name yet.
blTime = millis(); // can't discuss this line because you haven't changed the variable name yet.
lcd.backlight(); // Can you guess what belongs here ?
}
if (blOn == true && millis() - blTime > 10000) // Can you guess what belongs here ?
{
lcd.noBacklight(); // Can you guess what belongs here ?
blOn = false; // // Can you guess what belongs here ?
}
}
//==============================================
Change the variable names as you were instructed and we can proceed ...
This is the snippet we will modify as an example once you have changed the variablenames in the snippet I uploaded in my last post.
We will take that code and put it in the following code.
if(readString.indexOf("?relay1on") >0)//checks for on
{
digitalWrite(4, HIGH); // set pin 4 high
Serial.println("Led On");
client.println("<link rel='apple-touch-icon' href='http://chriscosma.co.cc/on.png' />");
//client.println("Light 1 Is On");
client.println("
");
}
else{
if(readString.indexOf("?relay1off") >0)//checks for off
{
digitalWrite(4, LOW); // set pin 4 low
Serial.println("Led Off");
client.println("<link rel='apple-touch-icon' href='http://chriscosma.co.cc/off.png' />");
//client.println("Light 1 Is Off");
client.println("
");
}
Just for the record, in case it has not occurred to you, when you post on this forum , there is more going on that just the project that you are posting for. This is a help forum. If you everyone were only allowed one post per lifetime then there would be no need to train them on how to use this forum. Obviously that is not the case. So when you post about a project to build a watering timer for your grandma, you are also learning how to use this forum so you won't waste our time and force us to play 20 questions next time. Part of this learning process is you understanding that we are not psychic and cannot read your mind. When you say you can't do something or don't understand something, we don't know why so it makes it very difficult for us to help you. When I post an example sketch that contains variables you don't understand, you are supposed to ask what they mean.
ie:
What is "blstatus " for ?
etc..
There is no point in plugging code from your sketch into a sketch that has variable names that have nothing at all to do with your sketch. You were asked to changed the names and didn't. Skipping that step is not shortening the solution for you. It is only making it longer because I am forced to ask you again. This will go on forever until it is done. We cannot skip that step any more than you could skip that step when you wrote your sketch. In short, when you post for the first time there are many things you need to know:
Most if not all of them are listed here:
http://forum.arduino.cc/index.php/topic,148850.0.html
In a nutshell it says :
1-Present ALL the necessary information on your first post (code, schematics , photos, etc)
2- If you don't understand a reply, ASK QUESTIONS
3- If you are asked to do something , do it, or give a good reason why you cannot.
FYI,
Just for the record, software is not my area of expertise. My specialty is hardware. I am doing the best I can with my limited programming skills but I understand the basics, (like declaring variables with appropriate names BEFORE modifying code).
Robin is probably better suited to help you but the last time I said "Robin can help you" he didn't appreciate me dumping the whole mess on his plate and running off ......so I will just say, if you don't find my input helpful , just say so and I'll bail..