Pause function in loop

Again, maybe I need advice about the stupid questions.
How is made a pause in programu.Funkce “delay” as it is known slows down the whole program.
I’m at the beginning of the loading analog functions “Millies ()” every 10 seconds.
Then I have a program that ties together, but I need to insert pauses for each selected step. And, unfortunately, I do not know how. Because the “delay” generally slows down the whole loop.

for example

int sensorPin = A0;    
int ledPin = 13;      
int ledPin2 = 12;
int sensorValue;  
long zaznam = 0;
int mapaTeplotaIn;
void setup() {
  pinMode(ledPin, OUTPUT);  
   pinMode(ledPin2, OUTPUT);

void loop() {
unsigned long odpocet = millis();   

 if(odpocet - zaznam > 500) {                                  
    zaznam = odpocet;   
sensorValue = analogRead(sensorPin);                       
mapaTeplotaIn = map(sensorValue, 0, 1023 , 370, 450);   }       


if(mapaTeplotaIn < 390){
 delay(5000);                                 //here is problem , It also slows down the loading of the analog input
if(mapaTeplotaIn > 390){
  delay(5000);                               //here is problem


Check the blink without delay example on the tutorial pages how you can schedule pauses and timed events without using delay() at all.

I've not exactly understood the question but from what I can infer try putting the delay() after the digitalWrite(), That should keep the LED state and wait for 5secs.

the "millis" I have tried but I can not do the same each time interval is different; If you turn the potentiometer.

I is not about any move. It is a fact that if you use several delay for each result is cumulative. And I want to read in analog faster. If necessary I use delay (5000) 3 times, the result is 15000 and this is reflected in the retrieval analog sensorValue.

And I want to read in analog faster. If necessary I use delay (5000) 3 times

You can do about 45000 analogReads in five seconds. Try not to use delay.

sheep: the "millis" I have tried but I can not do the same each time interval is different; If you turn the potentiometer.

Well, the whole idea behind the Blink Without Delay is that you can use millis() to see what time it is now, then set a duration, after which you do something. If you want different delay times, use different delay times. Variables can be used. Put a duration into a variable, and check to see if that time has passed. If you want a different duration, USE a different duration.

Can you tell us WHY you need a delay before doing an analogRead?

Because I have a thermometer which is not very accurate and responds to the slightest change in temperature that oscillates + / - 3 degrees. A beautifully slow down when loading stabilizes. The thermostat is a pretty important when I set hysteresis only 5 degrees. It is a thermocouple. The lower temperature using DS18B20 where this phenomenon is not. Measures and evaluates the temperature around 500C.A I drive it. It is a machine that performs several consecutive steps. And among them are the delays and if you use "delay" value adds up and slows down the whole program. And it happens that before all steps execute a running relay heating temperature rises faster than you can react to the condition of the thermostat off. This is not to be used to interrupt the action "delay" but something else that did not interrupt the loop.

OK, but the advice remains the same. Blink Without Delay will tell you how to time something.

You set a variable (call it startTtime) to the value of millis(). You set another variable to the length of time (in millisseconds). Call it Duration. When you get to the place where you want to do an analog read, you subtract startTime from millis(), and if the result is equal to or greater than Duration, you do your analog read. Otherwise, you carry on doing your other stuff.