SoapyBoat:
Void setup includes "Serial.begin (9600)", and void loop includes "Serial.println("Child alone in car!"). I believe those send it.
Well since your setup has sent it, there's no need to look to see if it's there.
This is the issue, you never need to look at the serial port to work out what you've sent because at the point you send it you know that you've sent it.
What ChilliTronix said. Also, since I've already written it...
millis() is an Arduino function that gives you the number of milliseconds that have passed since the last time the Arduino was reset, or connected to power.
So, for instance, if you want a LED to light up after one second* of resetting the Arduino, you'd write something like this:
// Here's a loop that waits until a second has passed
while (millis() < 1000) ;
// Now the loop has ended, time has come to light up the LED
Actually it'll be a bit longer, because the Bootloader runs for a little while after reset, and only then yields control to your own code.
Now let's say you want to measure 1 second from external event A, and then start event B:
unsigned long timeStamp;
// We learned that event A happened, so...
timeStamp = millis(); // record onset time of event A
// The waiting loop, checks current time against onset of A
while (millis() - timeStamp < 1000) {
// Do whatever you want while you're waiting
}
// Loop has ended, meaning a second has passed, fire up event B
igendel, what you are doing is essentially the same as using delay(), your code is doing nothing (and can't do) while waiting. The point of the Blink without delay example is to actually allow to make other things without blocking in a while loop.
guix:
igendel, what you are doing is essentially the same as using delay(), your code is doing nothing (and can't do) while waiting.
That was the first code in my reply, just to demonstrate what millis() is. The second one already has an option to do something while waiting - and, of course, one can change that "while" declaration into an "if" with the opposite condition, and no more blocking
SoapyBoat:
If the child has been placed in the seat, I don't want the light to go off, because the child has to be placed in the seat before the driver can sit. The LED is soon to be replaced with a motor that will vibrate, so I don't want to motor to vibrate just because the driver hasn't had a chance to sit.
Then you need to record in a variable the fact that you are sending the message and refer to that later if you need to check. Indeed you should use the variable to decide whether to send the message.
For example (these lines won't be one after the other)
boolean childInSeat;
childInSeat = true;
if (childInSeat == true) {
KenF:
Ah, I see, SoapyBoat has a point. You forgot to send it to the serial port
If this is a humorous comment I am perfectly happy.
If not, perhaps you would explain.
...R
PS Now that I have taken notice of the OP's name I can see why he is having a problem getting to grips with his project. But it's not worth getting into a lather over it.
How do I add a delay for "Child alone in car!" without stopping the entire program (so, using millis(), which I haven;t quite grasped the concept of.)
Suppose your girlfriend called, and said "Meet me at my place in three hours, for wild passionate sex". Knowing that it takes 10 minutes to get there, would you sit and stare at the clock for over two hours? Or would you continue with whatever you were doing for almost three hours?
Sitting and staring at the clock is what delay() does.
Doing other things, and occasionally looking at the clock, is what the blink without delay example shows. "The clock" is the millis() function. It returns a time. Record the time when the "child alone in car" event is first detected. Periodically, check the time (that is, on every pass through loop()), to see if the "child alone in car" event happened long enough ago to be a problem.
Obviously, "child alone in car" while "parent pumps gas into tank" is not a problem, but "child alone in car" while "parent plays bingo for two hours" is.
Say, 1350000) and use that as a delay for "Child alone in car!". This gives 22.5 minutes for the adult to finish pumping gas, or to get their child out of the car to bring them to daycare.
Fine. Then use delay(). But, you keep saying that you don't want to use delay.
I give up. I've done everything possible to explain how to use millis().