# Check For USB Port Connection

**URL:** <https://discourse.processing.org/t/check-for-usb-port-connection/17406>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [January 29, 2020, 3:49am UTC](https://discourse.processing.org/t/check-for-usb-port-connection/17406 "2020-01-29T03:49:34Z")\
**Posts on this page:** 2\
**Page:** 2

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [February 4, 2020, 4:34pm UTC](https://discourse.processing.org/t/check-for-usb-port-connection/17406/21 "2020-02-04T16:34:19Z")

</div>

> [@glv](#):
>
> I did put the whole serial initialization in a startup() function that can be called from setup() or in draw()

Setup is intended to run once and will not update canvas as draw() does:

> **[Processing Overview](https://processing.org/tutorials/overview/)**
>
> A little more detailed introduction to the different features of Processing than the Getting Started tutorial.

> **[setup() / Reference](https://processing.org/reference/setup_.html)**
>
> The setup() function is run once, when the program starts. It's used to define initial environment properties such as screen size and to load media such as images and fonts as the program start…

Here is a minimal version to run “something” at start of draw() before looping though main code in draw() :

```auto
//boolean choiceMade = false;
boolean startup = true;
boolean displayOnce = true;

void setup()
  { 
  size(300, 150);
  textAlign(CENTER, CENTER);
  textSize(48);
  }
  
void draw()
  {
  //Startup code runs once until a key is pressed
  if (startup) 
    {
    background(255, 0, 0);
    
    if (keyPressed) 
      {
      //choiceMade = true;
      startup = false;
      }
    
    text("Press a key", width/2, height/2-10);
    return; //https://processing.org/reference/return.html
    }
  
  //Main code
  background(0, 255, 0);
  text("Yay!", width/2, height/2-10);
  } 

```

’ 🙂 ’

---

<div class="post-metadata">

**Author:** ![fredstout](https://avatars.discourse-cdn.com/v4/letter/f/258eb7/32.png) [@fredstout](https://discourse.processing.org/u/fredstout)\
**Post date:** [February 4, 2020, 6:43pm UTC](https://discourse.processing.org/t/check-for-usb-port-connection/17406/22 "2020-02-04T18:43:34Z")

</div>

I must wait until I return from Switzerland to try this out. Please bear with mr, I will be gone for a month,

Fred

[Previous page](https://discourse.processing.org/t/check-for-usb-port-connection/17406.md?page=1)
