How To Use The Mills() Fonction

Hi! Can you please help me with my code?
I Made an Elevator Arduino Code and Used The Deley Fonction To Close The Door automatically after few seconds. it seemed to have worked but when I tried to go for the Mills approach my simulation ( wich was done it proteus 8 ) didn't work.

both my Codes are down Below , any help or advice will be much appreciated.

First Code :

void loop() { if (doorOpen && !doorClosing) { delay(doorDelay); closeDoor(); delay(50); } }

Converted To Mills () :

void loop()

{

static long doordelayMillis=millis();

static long closedoorMillis=millis();

if (doorOpen && !doorClosing && (millis()-doordelayMillis>doorDelay))

{

//delay(doorDelay);

if(millis()-closedoorMillis>50){

closeDoor();

//delay(50);

closedoorMillis=millis();

}

doordelayMillis=millis();

}

}

Check out my tutorial on How to write Timers and Delays in Arduino which has millis() sketches and other ways of writing various type of delays/repeats

The easier you make it to read and copy your code the more likely it is that you will get help

Please follow the advice given in the link below when posting code , use code tags and post the code here

@theguy171 Please post the complete sketch of your best attempt to use millis() for timing in your project

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.