Understanding Structure

The code below, the top two don't work, the last one dose.
can anybody please explain why?????

void delay_before_display() {

if(delay_time == 0) {
delay_time = millis() + 500; }
if(delay_time > millis()) { // if not go continue to lcd_update()
if(delay_time < millis()) { // if not go continue to lcd_update()
good_to_go = 500; // allow lcd_update()
delay_time = 0; }
}
} // end delay before display

void delay_before_display() {

if(delay_time == 0) {
delay_time = millis() + 500; }
if(delay_time > millis()) {
if(delay_time <= millis()) {
good_to_go = 500;
delay_time = 0; }
}
} //end delay before display

void delay_before_display() {

if(delay_time == 0) {
delay_time = millis() + 500; }
if(delay_time > millis()) { // if not go continue to lcd_update()
if(delay_time <= millis()) { // if not go continue to lcd_update()
good_to_go = 500; // allow lcd_update()
delay_time = 0; }
}
} // end delay before display

Thanks

I can't see any difference between your middle code and your last code.

If you use the AutoFormat tool to lay out your code consistently it will be much easier to read. Always ensure the every } is on a line of its own.

None of the examples is using millis() correctly.

Have a look at how millis() is used to manage timing in Several Things at a Time.

And see Using millis() for timing. A beginners guide if you need more explanation.

...R

Welcome to the group.

There is a 'Programming' forum on this site where questions like this should be asked.

I sort of made a mess of that, it should have read as follows.
I specifically want to know why this dose not work with the Arduino.

The second one is no = sign on line 7

The code below, the top two don't work, the last one dose.
can anybody please explain why?????

void delay_before_display()
{

if (delay_time == 0)
{
delay_time = millis() + 500;
}
if (delay_time > millis()) // if not go continue to lcd_update()
{
if (delay_time < millis()) // if not go continue to lcd_update()
{
good_to_go = 500; // allow lcd_update()
delay_time = 0;
}
}
} // end delay before display

void delay_before_display()
{

if (delay_time == 0)
{
delay_time = millis() + 500;
}
if (delay_time < millis())
{
good_to_go = 500;
delay_time = 0;
}
}
} //end delay before display

void delay_before_display()
{
if (delay_time == 0)
{
delay_time = millis() + 500;
}
if (delay_time <= millis())
{
good_to_go = 500;
delay_time = 0;
}

} //end delay before display

The rest of your code isn't there. You seem to be trying to hybrid millis() timing with delay() timing. This is sure to cause all sorts of problems. Try to change the logic of your program so that only a single timing method runs the system.

Robin's links above are 'da bomb!'

In the first version these two lines make a nonsense of each other

  if (delay_time > millis())
  {
    if (delay_time < millis())

In the second program there is one } too many

In any case I don't know what you want the program to do and you have not posted a complete program so we cannot see how the function is used.

As I said before, that is not the proper way to use millis()

...R

The question was, what is wrong with the top two groups of code, I am troubled because they don't work, to me they should, I would like to know so I do not make the same mistake again.

"The rest of your code isn't there. You seem to be trying to hybrid millis() timing with delay() timing"

The program is quite long.

The original ' delay_time ' is set in void setup.

The timer needs to run every loop until it achieves its set time, ' good_to_go ' then allows the LCD function to complete its task then reset the variables ready to run again on the next loop. the LCD updates twice a second

With the last piece of code it runs fine, but with the extra ' if ' statement and the lack of the ' = ' the don't work, WHY ????

Take out the extra bracket (wont compile with it anyway) it still won't run.

I understand that the one of the " if ' statements is unnecessary, even so the the code to me should work

Brinks:
Take out the extra bracket (wont compile with it anyway) it still won't run.

"still won't run" makes no sense without seeing the complete program. The problem is probably in the part you are not looking at.

I understand that the one of the " if ' statements is unnecessary, even so the the code to me should work

If you have contradictory IF statements then "should work" can only translate into "do nothing".

I'm beginning to think the real problem here is that we have no idea what you think should be happening.

If you have any further questions please accompany them with a complete program that illustrates the point you want help with.

...R

The complete program to date still a work in progress

SketchReflowNew 2.txt (9.64 KB)

Brinks:
The timer needs to run every loop until it achieves its set time, ' good_to_go ' then allows the LCD function to complete its task then reset the variables ready to run again on the next loop. the LCD updates twice a second

This is the basic blink without delay, where blink is the LCD display function and the blink rate is 500mS.

/*
  Blink without Delay

  Turns on and off a light emitting diode (LED) connected to a digital pin,
  without using the delay() function. This means that other code can run at the
  same time without being interrupted by the LED code.

  The circuit:
  - Use the onboard LED.
  - Note: Most Arduinos have an on-board LED you can control. On the UNO, MEGA
    and ZERO it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN
    is set to the correct LED pin independent of which board is used.
    If you want to know what pin the on-board LED is connected to on your
    Arduino model, check the Technical Specs of your board at:
    https://www.arduino.cc/en/Main/Products

  created 2005
  by David A. Mellis
  modified 8 Feb 2010
  by Paul Stoffregen
  modified 11 Nov 2013
  by Scott Fitzgerald
  modified 9 Jan 2017
  by Arturo Guadalupi

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
*/

// constants won't change. Used here to set a pin number:
const int ledPin =  LED_BUILTIN;// the number of the LED pin

// Variables will change:
int ledState = LOW;             // ledState used to set the LED

// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0;        // will store last time LED was updated

// constants won't change:
const long interval = 1000;           // interval at which to blink (milliseconds)

void setup() {
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // here is where you'd put code that needs to be running all the time.

  // check to see if it's time to blink the LED; that is, if the difference
  // between the current time and last time you blinked the LED is bigger than
  // the interval at which you want to blink the LED.
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW) {
      ledState = HIGH;
    } else {
      ledState = LOW;
    }

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
  }
}

Tom... :o

Brinks:
The complete program to date still a work in progress

I think your whole concept is mistaken.

Looking at your code in loop()

void loop() {

  delay_before_display();
  lcd_update();
  delay_before_read();
  get_temp();
  reflow_update();
  // etc

it seems to me you are just trying to create a function that behaves the same way as the regular delay() function.

If the program has nothing else useful to do before the get_temp() function then it makes sense just to use delay().

However if you want the program do do other things while it is waiting to take the temperature then your code needs to be something like this

void loop() {

  delay_before_display();
  lcd_update();
  if (millis() - prevTempReadMillis >= tempReadInterval) {
     prevTempReadMillis += tempReadInterval;
     get temp();
   }
   reflow_update();
   // etc

And, by the way, when you are unsure of how to do something learn about it first on a very short complete program - for example one that just prints a message at appropriate intervals.

...R

Thanks for your help