Guys I need help,
This stuff if frustrating.
How is it that those examples given can assist me? none of them show how to create the different delays. I need some kind of delay1+delay2
I am not seeing any way to make millis do as my delay does above, having the two different values.
I have been playing around with the code,
all the examples just use repeating values. like millis delay1 2000ms, meaning reoccurs at (2,4,6,8s etc) I need the delay2 factored into the timing to alter delay1. to add the 500ms on top.
if I add code to double up and have millis delay2 at 2500ms, (2.5s, 5s, 7.5s) works fine first time (delay1=2s, delay2=2.5s), but then the timing is way off. delay1=4s, delay2=5s. Then more off. delay1=6s, delay2=7.5s
as millis repeats the timed event, I am not sure how to stack the time. for example millis delay1 + millis delay2
I am also concerned for if the delay1 changes from 2000ms to 3000ms I would for coding sake want the delay2 added to delay1, creating a situation that needs the LED to turn off at 3500ms.
eg: this was a good example of showing what millis can do, the repeated delayed messages, I simply added line to turn on and turn off the LED. .
/*
int ledPin = 13; // LED connected to digital pin 13
#define INTERVAL_MESSAGE1 2000 // turn on for 2000ms
//#define INTERVAL_MESSAGE2 500 //THIS REPEATS EVERY 500MS :(
#define INTERVAL_MESSAGE2 2500 //THIS REPEATS EVERY 2500ms works fine first time.
unsigned long time_1 = 0;
unsigned long time_2 = 0;
void print_time(unsigned long time_millis);
void setup() {
Serial.begin(115200);
}
void loop() {
if(millis() >= time_1 + INTERVAL_MESSAGE1){
time_1 +=INTERVAL_MESSAGE1;
print_time(time_1);
Serial.println("Light On");
digitalWrite(ledPin, HIGH);
}
if(millis() >= time_2 + INTERVAL_MESSAGE2){
time_2 +=INTERVAL_MESSAGE2;
print_time(time_2);
Serial.println("Light Off");
digitalWrite(ledPin, LOW);
}
}
void print_time(unsigned long time_millis){
Serial.print("Time: ");
Serial.print(time_millis/1000.00);
Serial.print("s - ");
}
*/
I was looking to see if I can somehow make the delay2 stack on top of the delay1 by trying lines like this
time_2 +=INTERVAL_MESSAGE2 + INTERVAL_MESSAGE1;
the 2000ms and 500ms will when my project is complete would vary with adjustable potentiometers and I would like to find a way to make both the delays know what the other is doing.
basically want to use delay which may be variable, but using millis in it's place as I might want to run another code while thats occuring instead of using two arduinos.
Also, I taken a look at the blink without delay,
I understand that the blink without delay using if commands, I would like to avoid if command
I am so lost.
Regards,
Shaun.