I want to remove this delay(); before I freak

Hi I got this thing going on that require time precision and I feel that the delay() that is there is eating some of it. Basically I literally want to blink with out delay() but this one is warping my mind into a inward loop :wink:

Please help!!!

Basically this part of the code is in a void() that is being call in a time regular repetition:

for (byte position_actuel = 0; position_actuel < position_du_caractere; position_actuel ++){
  
    digitalWrite(broche_position[position_actuel - 1], HIGH);
    digitalWrite(broche_position[position_actuel], LOW);
    
    for (byte segment_actuel = 0; segment_actuel < nombre_de_segment; segment_actuel ++){
    
      if ((segment_actuel == 7) && (position_actuel == 1)){digitalWrite(broche_segment[segment_actuel], affichage_seconde);}
      else {digitalWrite(broche_segment[segment_actuel], !caractere[affichage[position_actuel]][segment_actuel]);}
              
    }  
    
    delay (5);

}

And I want in some way to remove the delay(5) at the end. Any one has any Idea?

This little part of code his meant to run a 4 X 8 segments module by the way

5 ms is a pretty short delay. Try just removing it. It is the delay(500)'s that eat up a lot of time!

Posting a snippet does not tell us why that delay might be needed. Post your whole sketch.

I was just about to say what Keith said. 5 millis is a pretty short time. I'm not sure you'd notice just taking it out.

Also it's not a void() it's a function. void in front of a function indicates that the function doesn't return a value. It's the return type for the function.

Jimmy60:
Also it's not a void() it's a function. void in front of a function indicates that the function doesn't return a value. It's the return type for the function.

Huh? That's perfectly commonplace language when talking about C, just like describing
a variable as a "char *". We know what it means.

In C the lack of a return statement indicates that the function doesn't return a
value, whatever its declared to do! (especially if compiler warnings are suppressed).

Well the delay(5) is basically giving just enough time so the segment of the display that should be OFF are OFF. If I remove the delay(5) some segment that should not be ON, are ON.

I'm using this display module,

4x8.JPG

witch is driven by transistor for allimentation, and I'm starting to believe that those transistor are slow to react, so the delay is required.

Some thing is not clear in the reference. Does delay() function influence the outcome of the millis() function??

Won't change much but here is the whole function :wink:

void gestion_affichage(){

  analogWrite(broche_luminosite, luminosite);
    
  for (byte position_actuel = 0; position_actuel < position_du_caractere; position_actuel ++) {
  
    pinMode(broche_position[position_actuel], OUTPUT);
    digitalWrite(broche_position[position_actuel], HIGH);
  
  }
  
  for (byte position_actuel = 0; position_actuel < position_du_caractere; position_actuel ++){
  
    digitalWrite(broche_position[position_actuel - 1], HIGH);
    digitalWrite(broche_position[position_actuel], LOW);
    
    for (byte segment_actuel = 0; segment_actuel < nombre_de_segment; segment_actuel ++){
    
      if ((segment_actuel == 7) && (position_actuel == 1)){digitalWrite(broche_segment[segment_actuel], affichage_seconde);}
      else {digitalWrite(broche_segment[segment_actuel], !caractere[affichage[position_actuel]][segment_actuel]);}
              
    }  
    
    delay (5);

  }   
      
}

I know it's in french, but just revers the noun and adjective, and replace the termination "...el" by "...al" and you will all be fine. Or two language are pretty much the same in the big words after all.

Frédéric_Plante:
Some thing is not clear in the reference. Does delay() function influence the outcome of the millis() function??

The answer is no, the delay() has no effect on millis() so I'm gonna calculate time another way.

You know what the whole program does but we don't. So the pieces you are showing us are of little use for getting good advice. You need to give us a good description of the whole system so we know what you are talking about. Really, you should post the entire sketch, not just a snippet.

If you have a very long program I'm probably not going to take the time to read it and if you have specialized hardware I can't try it on my Uno or Mega. In that case maybe you could produce a short sketch that illustrates the problem.

...R