# Delay in a map function

**URL:** <https://forum.arduino.cc/t/delay-in-a-map-function/1302402>\
**Category:** Programming\
**Created:** [September 17, 2024, 8:51am UTC](https://forum.arduino.cc/t/delay-in-a-map-function/1302402 "2024-09-17T08:51:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![petercl14](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/petercl14/32/1013044_2.png) [@petercl14](https://forum.arduino.cc/u/petercl14)\
**Post date:** [September 17, 2024, 8:51am UTC](https://forum.arduino.cc/t/delay-in-a-map-function/1302402/1 "2024-09-17T08:51:20Z")

</div>

Is it valid programming to include a delay in a map function? Like this;  
y=map(x,70,0,delay(0),delay((z\*55.55); //z\>100  
I have include 70 here which is actually a variable, will not always be 70. I could have used 'm' for example. Too many variables makes for confusion as some have told me on this forum.

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [September 17, 2024, 8:52am UTC](https://forum.arduino.cc/t/delay-in-a-map-function/1302402/2 "2024-09-17T08:52:57Z")

</div>

The delay() function does not return a value so what you are trying is nonsense

What is it that you want to achieve ?

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [September 17, 2024, 8:57am UTC](https://forum.arduino.cc/t/delay-in-a-map-function/1302402/3 "2024-09-17T08:57:49Z")

</div>

if you want a variable delay based on map, you need to write this differently

is this what you want to achieve ?

```arduino
delay(map(x,70,0,0,z*55.55));

```

that would say create a linear function that goes through (70, 0) and (0, z\*55.55) and find the y for the variable x on that line to calculate the delay.

---

<div class="post-metadata">

**Author:** ![petercl14](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/petercl14/32/1013044_2.png) [@petercl14](https://forum.arduino.cc/u/petercl14)\
**Post date:** [September 20, 2024, 6:35am UTC](https://forum.arduino.cc/t/delay-in-a-map-function/1302402/4 "2024-09-20T06:35:19Z")

</div>

problem fixed Bob. I should have seen it before. You are right it would not work like that. I will just enter the numbers. Then when I have 'y' I will use 'delay y'.  
If I tried to explain what I hope to achieve this topic would go on too long. It is best just to fix one small part of a complicated sketch at a time.

---

<div class="post-metadata">

**Author:** ![petercl14](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/petercl14/32/1013044_2.png) [@petercl14](https://forum.arduino.cc/u/petercl14)\
**Post date:** [September 20, 2024, 6:53am UTC](https://forum.arduino.cc/t/delay-in-a-map-function/1302402/5 "2024-09-20T06:53:00Z")

</div>

Kind of like that. Just using the numbers in the map function. Then getting the value of "y". Then using 'delay y'. The way I put it first would not work. The numbers give a delay time for the rest of the sketch. z should be z=1000 to convert seconds to milliseconds to work in the delay function in Arduino.

---

<div class="post-metadata">

**Author:** ![jimLee](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jimlee/32/214865_2.png) [@jimLee](https://forum.arduino.cc/u/jimLee)\
**Post date:** [September 20, 2024, 6:58am UTC](https://forum.arduino.cc/t/delay-in-a-map-function/1302402/6 "2024-09-20T06:58:58Z")

</div>

The entire reason for programming code to exist, is to make what's going on easy to understand for humans. DON'T GET ALL CLEVER AND TRIXY WITH IT.

-jim lee

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 19, 2025, 6:59am UTC](https://forum.arduino.cc/t/delay-in-a-map-function/1302402/7 "2025-03-19T06:59:20Z")

</div>

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