Delay

Is there a way to create a delay without useing Delay()?

I have Data reporting every second. I also have a Digi pin go HIGH for 5 seconds every 10 min. However, when this pin is high the data reporting stops until that function returns 5 seconds later.

So I’m either missing something simple or that is the way it is.

Of course there are ways to delay with using delay(). Look at the Blink Without Delay example sketch that is part of the Arduino IDE package.

Excellent, Thanks

guess it would do me good to go threw all the examples ;)

Dumb question,

Description Long variables are extended size variables for number storage, and store 32 bits (4 bytes), from -2,147,483,648 to 2,147,483,647

So what happens when the variable gets above 2,147,483,647?

Does it wrap around back to 0?

2,147,483,647 + 1 = 0 2,147,483,647 + 2 = 1

:-?

What is this, PaulS, noob-baiting?

Well thanks, but thats a no-go.

Doing that for what ever reason knocks out serial communication unless it is just a single letter command.

EDIT This creats a timing issue of some sort. If I delay the loop by a 10th of a second, all works again.

Well thanks, but thats a no-go.

What is "that"?

Doing that for what ever reason knocks out serial communication unless it is just a single letter command.

Is this a different that from that that?

Take a deep breath, relax, post your code, and explain the problem a little better.

Can't post the whole thing, but in part;

void loop()
{
  // Listen for Incoming data
  if(Serial.available() > 0)
    {
    // First byte is Command type
    c = Serial.read();
    switch(c)
      {
      case 'P': Purge(2500);break;
      // case 'R': iR_State = SetRelay();break;
      case 'S': SetTankSpan(); break;
      default: break;
      }
    Serial.flush();
    }
  delay(100);
  // Data Start
  if(millis() - PreMillis > REPORT_TIME)
    {
    PreMillis = millis();
    ReportData();
    }

Without the delay(100); in there, the SetTankSpan() function call gets inturupted by the ReportData() function call. The SetTankSpan() call reads more incoming data where ReportData() sends data out the com port.

case 'P' still functions with or without the delay but case 'S' is followed by more data.

EDIT It must be looping back before the SetTankSpan() function can finish. only thing I can think of.

The first thing I see when I look at this code is this:

    Serial.flush();

Please tell me you know what this function does, and why you need to use it.

We need to see the code for the SetTankSpan() function. Your surmise that SetTankSpan is returning before you expect it to is probably correct. There is either a problem with the code or a problem with your expectations. Need to see the code to know which is correct.

The most likely cause is that serial data transmission is relatively slow, while reading serial data is not. It is likely that SetTankSpan runs out of data to read before it reads all the data that it needs to.

Is there some marker in the data stream that tells SetTankSpan when it has read enough data?

Please tell me you know what this function does, and why you need to use it.

It clears the serial buffer does it not? Maybe a batter place would be after the default for the switch/case?

Anyways, everything worked until I stared countnig the milliseconds.

Take a look at your message box, I sent you a PM.

It clears the serial buffer does it not?

Yes, it clears the serial buffer.

You have attached something to the Arduino, and arranged for it to send serial data.

There is no handshaking going on. That is, the device sending serial data is not sending it specifically in a request for data. It is sending it at its own pace. Periodically, you dump random amounts of data that the device has sent.

I say random amounts because you have no idea, when you call Serial.flush() whether there are 0 bytes or 100 bytes. You don't read and ignore complete packets. You just pull the plug and drain the serial buffer of whatever data it held.

Unless you understand that this is what you are doing, and there is good reason for doing this, it is generally a bad idea to do this.

2,147,483,647 + 1 = 0

What is this, PaulS, noob-baiting?

;D

Unless you understand that this is what you are doing, and there is good reason for doing this, it is generally a bad idea to do this.

Understood.