Is there anything i can add into the above code to simply prove it works before i write something more specific? if so, where exactly is best to insert it?
but i'm having great difficulty finding a way of extracting the numerical values.
OK. Lets work through this.
- Detecting when when receivedChars[1] == '3' and receivedChars[0] == '0'?
The test for the time match needs to be when newData == true.
If you don't want to convert the chars to the actual number 30 like in the previous code, then you can use a compound conditional statement like
if(receivedChars[1] == '3' && receivedChars[0] == '0')
{
//do what needs to be done at a time match
}
The && is the syntax for "logical and" and it means both conditions need to be true for the statement to be true. The Arduino ide, even makes it easier, and you could use the word "and" if the && confuses you.
The "devil is in the details" of this code is when to set the newData flag back to false, and what do you want to do on the time match.
Depending on the relay action, there are different ways to go and different times to set the newData flag back to false. My preferred method would be to use a new boolean flag variable runRelayCycle. I'd set it true on the match and then set newData = false.
if(receivedChars[1] == '3' && receivedChars[0] == '0' && runRelayCycle ==false)
{
runRelayCycle = true;
newData = false;
}
- Your next issue is what to do with the relay when the time match occurs.
All the relay timing and setting the runRelayCycle condition back to false, so that you can act on the next time match, will be in a new conditional statement.
Most important is how long does the relay need to be on, and if you need to turn it on and off with non blocking techniques using a millis() timer instead of delay()?
There are some details here if to make the timing non blocking but lets deal with that when you get the time match part of the code under your belt. Conceptually, the relay code will be like this
if(runRelayCycle ==true)
{
//turn relay On
//start timing
//turn relay Off
//runRelayCycle = false
}
See if you can come back with some code which implements the match on 30 seconds, and we'll go from there.