delay (time in ms) doesnt work

I have a ProMini 168 and am nearly finished with a project except there is an unusual bug with a simple delay (1000) ; // 1 second interval command
I noticed that the main loop runs about 10 times faster than expected and the delay() command has no effect on it. I also wrote a test program where the time on is the absolute minimum (1) and time off is 100000. The LED is on just as bright as ever. The scope indicates its driven constantly on. The simplest of functions are normally the problem.

delay() works just fine. Your code is wrong....

Regards,
Ray L.

I can assure you that the delay() function works as documented. If it does not meet your expectations, either your expectations or your code (or both) are incorrect.

millis() is the better way of doing timing. See the forum for examples

What happens if you upload File > Examples > 01.Basics > Blink?

fnb111:
millis() is the better way of doing timing.

Even if that’s true, your comment is irrelevant in the context of the OP’s issue. He or she evidently has some issue with some code, perhaps a misunderstanding of what delay() does, or a mis-placement of the command in the code, who knows, and that issue needs to be addressed even if millis() is “the better” (for some definition of “better”) way.

Nemere should post his or her code…

I have tried everything I could but delay() makes no difference on my Arduino ProMini 168
So I tried milli and that also either hangs or does nothing. So I am including a snipet of my code so that we can get to the bottom of the problem. This is but one of many tries.

unsigned long startMillis;
unsigned long currentMillis;
unsigned long period = 1000;
//===========================================================
// Oven
// Temperature adjust and measurements
//
//===========================================================
void Oven (void)
{
startMillis =millis(); //current time
while (millis() < startMillis + period ) ← this should time out before continuing with rest

if (TimeAccum >= (Timer[Segment+1])) //TimeAccum was less then segment
{
Segment ++;
digitalWrite(Buzzer, HIGH);
TempSlope = Slopr[Segment]; //slope *128 scale
TempAccum = Tempr[Segment] * 128;
TimeAccum = Timer[Segment];

Here is a snippet of my answer: Because

Please remember to use code tags when posting code

Well I can clearly see why delay() isn't doing anything in that code snippet. You forgot to write any delay()s into it.

Steve

As weird as it sounds neither delay() or millis() works which makes me wonder if there is some resource of the chip that I am using that disables it???

unsigned long previousMillis;
unsigned long currentMillis;
unsigned long period = 1000; 
//===========================================================
//     Oven 
//    Temperature adjust and measurements
//    
//===========================================================
void Oven (void)
 {
   currentMillis = millis(); // grab current time
   if (( currentMillis - previousMillis) >= 1000)
     {
       previousMillis = millis();
     }
    
     
   if (TimeAccum >= (Timer[Segment+1])) //TimeAccum was less then segment
       {
       Segment ++; 
</>
 in another location I have a test for delay() which also does nothing to the LED
</>
 case 4:  
            {
            for (i=0; i< 10000; i+=100)
              {  
               digitalWrite (DD_SCLK, HIGH); //DD_SCLK also connected to LED on pin 13
               delay (i);
               digitalWrite (DD_SCLK, LOW);
               delay (10000);
              }
            }

What is the proper Code Tag??

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

I did a test of the millis() readback data and its unchanging in a loop that displays its value.

Nemere:
What is the proper Code Tag??

Click the button. Don’t type what is displayed on its face.

Or, put your code between these…

</mark> <mark>[code]</mark> <mark>
code goes here
</mark> <mark>[/code]</mark> <mark>

I tried an example code by itself and it worked fine. However the same code inside my program didnt work

unsigned long previousMillis=0;
unsigned long currentMillis;
unsigned long period = 1000; 
//===========================================================
//     Oven 
//    Temperature adjust and measurements
//    
//===========================================================
void Oven (void)
   {                                 //simple 1 sec delay, doesn't work
   previousMillis=millis();
   if (currentMillis=millis() - previousMillis >= period) ;

Nemere:
I tried an example code by itself and it worked fine. However the same code inside my program didnt work

The code you just posted doesn't compile. Therefore, by definition, it doesn't "work". Either post a complete code and explain what you mean by "doesn't work" or stop wasting people's time.

In that last snippet you set previousMillis to millis() then currentMillis to millis() which is unlikely to have changed in one line so you're subtracting a value from itself which will always be zero.

Setting previousMillis to millis() should be inside the if, not before, ready for the next go thru loop().

But it's unclear now if you have a problem with millis() or delay() or both.

Frustrating isn't it. The subject line says that delay() doesn't work but the OP won't post any code with delay() in it so we that can see what he's doing wrong. Then the switch to millis() but refusing to post complete code.

Anyone else starting to think it's just another troll?

Steve

neither the delay or milis works inside my program as a subroutine. It works by itself. I have SPI also enabled and perhaps that prevents it from working. The latest example and I've tryed most is an example program that works standalone but not in the example.
[case]
case 4:
{

do{
blink();
hex2asci(millis()); //note that this is allways a constant 100
OLED_string_wr(" ");
}
while (1);
}
. . .

void blink()
{
// unsigned long current = millis();
if (current - previous >= 1000)
{
previous =current ;
if (ledState== LOW)
{
ledState = HIGH;
OLED_data_wr('H');
}
else
{
ledState = LOW;
OLED_data_wr('L');
}
digitalWrite(DD_SCLK, ledState);
}
}
[/case]

Presumably you meant those tags to be code not case....

You should post the whole program if your are interested in more than guesses.

You are wasting time.

Ah I see your problem. You're absolutely right millis() doesn't work if you have commented out the only line in the function where it would have been used.

Glad we've solved that for you then.

Steve