# Multiple Statements to a Loop

**URL:** <https://forum.arduino.cc/t/multiple-statements-to-a-loop/985424>\
**Category:** Programming\
**Created:** [April 26, 2022, 8:02pm UTC](https://forum.arduino.cc/t/multiple-statements-to-a-loop/985424 "2022-04-26T20:02:37Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![StefanL38](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/stefanl38/32/713548_2.png) [@StefanL38](https://forum.arduino.cc/u/StefanL38)\
**Post date:** [April 27, 2022, 4:42am UTC](https://forum.arduino.cc/t/multiple-statements-to-a-loop/985424/11 "2022-04-27T04:42:19Z")

</div>

You can imagine analogWrite as switching on with different intensity.

analogWrite(vm,255) : output "Full power"

analogWrite(vm,127) : output "half power"

analogWrite(vm,63) : output "25% power"

analogWrite(vm,0) : output "0% power" which is equivalent to switch off

So making your motor vibrate in a pattern similar to

1. vibrate for 2 seconds
2. stop for 3 seconds
3. vibrate for 5 seconds
4. stop for 1 second

would be

analogWrite(vm,255); // vibrate  
delay(2000);  
analogWrite(vm,0); // stop  
delay(3000);  
analogWrite(vm,255); // vibrate  
delay(5000);  
analogWrite(vm,0); // stop  
delay(1000);

If you want to do something in **parallel** to the vibration-pattern you can **not** use delay()  
because delay() is blocking.

Then you need **non** -blocking timing

digitalWrite(vm,HIGH) ; // output 100% power  
digitalWrite(vm,LOW) ; // output 0% power = **zero** power

**EDIT:** the explanation inside of the standard blink without delay provided by the Arduino-Website is

## really poor

I really would like to see the Arduino-Website team to **improve** this example to make it **easy** to understand. The reason is: it does not explain the basic principle on an everyday analogon.

As long as this hasn't happend I recommend reading this explanation instead:

> [@Example-code for timing based on millis() easier to understand through the use of example-numbers / avoiding delay()](https://forum.arduino.cc/t/example-code-for-timing-based-on-millis-easier-to-understand-through-the-use-of-example-numbers-avoiding-delay/974017):
>
> non-blocking timing. Execute code only from time to time. There are a lot of different ways to learn programming. This thread wants to add another approach that is different to the yet existing ones. UPDATE 06.01.2023 if you are mainly interested in applying non-blocking timing you can do a quick read of this short tutorial / demonstration If you are intersted in understanding the details how it works go on reading here. I use an everyday analogon in this post to explain the basic principle …

best regards Stefan

---

_[View the full topic](https://forum.arduino.cc/t/multiple-statements-to-a-loop/985424)._
