# Wait between port writes

**URL:** <https://discourse.processing.org/t/wait-between-port-writes/32550>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [October 1, 2021, 4:32pm UTC](https://discourse.processing.org/t/wait-between-port-writes/32550 "2021-10-01T16:32:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![PaladinBobcat](https://avatars.discourse-cdn.com/v4/letter/p/9d8465/32.png) [@PaladinBobcat](https://discourse.processing.org/u/PaladinBobcat)\
**Post date:** [October 1, 2021, 4:32pm UTC](https://discourse.processing.org/t/wait-between-port-writes/32550/1 "2021-10-01T16:32:37Z")

</div>

> please format code with \</\> button \* [homework policy](https://discourse.processing.org/faq/#homework) \* [asking questions](https://discourse.processing.org/t/2147)

I’m trying to figure out a way to wait a certain amount of time between sending serial data to my arduino.

I want to be a able to “animate” what gets sent through serial by pressing a button and waiting in between each port.write(). Is there a way to do this in Processing, or is there another program I can use to send serial seperately in a timed way like this?

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [October 2, 2021, 1:04am UTC](https://discourse.processing.org/t/wait-between-port-writes/32550/2 "2021-10-02T01:04:13Z")

</div>

Hi

You can use delay or millis

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [October 2, 2021, 1:22am UTC](https://discourse.processing.org/t/wait-between-port-writes/32550/3 "2021-10-02T01:22:53Z")

</div>

Try this example with and without delay

There is other many ways to do what you want

```auto
void draw() {
  if (mousePressed == true) {
    
    delay (1000);
    fill(0,255,0);
  } else {
   
    fill(0,0,255);
  }
  rect(5, 5, 150, 150);
}

```

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [October 2, 2021, 1:59am UTC](https://discourse.processing.org/t/wait-between-port-writes/32550/4 "2021-10-02T01:59:34Z")

</div>

This is other example for time delay using millis

```auto
int start;
int duration = 1500;
void setup() {
  size(600, 600);
  start= millis();
}
void draw() {
   int count = millis() - start;
  if (count> duration) {
    fill(0,255,0);
    rect(0,0,600,600); 
  }
}

```

---

<div class="post-metadata">

**Author:** ![RichardDL](https://avatars.discourse-cdn.com/v4/letter/r/f475e1/32.png) [@RichardDL](https://discourse.processing.org/u/RichardDL)\
**Post date:** [October 3, 2021, 7:56pm UTC](https://discourse.processing.org/t/wait-between-port-writes/32550/5 "2021-10-03T19:56:37Z")

</div>

Hi @PaladinBobcat, if you look at my [example](https://discourse.processing.org/t/processing-and-arduino-serial-example/31650) you’ll see it sends on every other draw(); The decision can easily be changed to other logic.
