Hi There ,
I need your help please to delay the code
when the green will be low I need to delay for 1 minute before make the relay low using millis
thanks in advance for help
int RED = 15;
int Green = 18;
int Relay = 12;
int Input = 4;
int state = LOW;
int val = 0;
void setup() {
pinMode(RED, OUTPUT);
pinMode(Green, OUTPUT);
pinMode(Relay, OUTPUT);
pinMode(Input, INPUT_PULLUP);
Serial.begin(9600);
}
void loop(){
val = digitalRead(Input);
if (val == HIGH) {
digitalWrite(RED, LOW);
digitalWrite(Green, HIGH);
digitalWrite(Relay, HIGH);
delay(100);
if (state == LOW) {
Serial.println("Motion detected!");
state = HIGH;
}
}
else {
digitalWrite(RED, HIGH);
digitalWrite(Green, LOW);
delay(700);
**digitalWrite(Relay, LOW);** **<...... need the Delay here**
delay(20);
if (state == HIGH){
Serial.println("Motion stopped!");
state = LOW;
}
}
}
This is a too short description to be understandable what you really want.
Please describe in normal words why it is nescessary to have a non-blocking delay here
What parts of your code have to continue to execute so that you need a non-blocking delay?
Or
do you simply need a blocking delay of 60000 milliseconds?
Thank you for your response
The reason of using millis that during the loop , while the red is delay, if the input status will be changed from low to high will be waiting and sometime will ignore until the loop will be completed
I will appreciate if you find a solution other than millis
I don't understand what you want to say with that.
since when can a color be delayed???
there is a variable name for that use it
Do you want it to be ignored?
or
does it happen and you don't want it to be ignored?
will ignore exactly what?
make a new try and describe the two different cases step by step and with exactly specifying every detail
If you post two sentence after 30 seconds all that happend is that you will have to wait 10 minutes until you receive new detail-questions and then you will have to invest 5 to 10 minutes anyway for a detailed answer.
So save 10 minutes and write the detailed and step by step description that names all details with your next posting
Take some time to design and code a state change detector for the variable "val". With this detector, the programme parts will only run when the variable "val" changes its state. This means that you do not need to call an additional delay() function.