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
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
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
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.
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 ????
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);
}
}
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.