# Posenet with p5js

**URL:** <https://discourse.processing.org/t/posenet-with-p5js/21009>\
**Category:** Libraries\
**Created:** [May 18, 2020, 10:05am UTC](https://discourse.processing.org/t/posenet-with-p5js/21009 "2020-05-18T10:05:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![babyP5](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/babyp5/32/9257_2.png) [@babyP5](https://discourse.processing.org/u/babyP5)\
**Post date:** [May 18, 2020, 10:05am UTC](https://discourse.processing.org/t/posenet-with-p5js/21009/1 "2020-05-18T10:05:11Z")

</div>

hello everyone im working on a project with posenet and p5js and i want when my hand is above my shoulder i append a number inside of an array the porblem is its keep adding the number multiple times before stoping and my goal is to just add it one time anyone here have an idea to stop it.

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [May 18, 2020, 10:17am UTC](https://discourse.processing.org/t/posenet-with-p5js/21009/2 "2020-05-18T10:17:08Z")

</div>

Hi,

The solution is to use a boolean value :

```auto
var inserted = false;

if(hands above your shoulder){
  // If you didn't already inserted a number
  if(!inserted){
    // Insert your number here
    inserted = true;
  }
}else{ //Otherwise set inserted to false
  inserted = false;
}

```

---

<div class="post-metadata">

**Author:** ![babyP5](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/babyp5/32/9257_2.png) [@babyP5](https://discourse.processing.org/u/babyP5)\
**Post date:** [May 18, 2020, 10:18am UTC](https://discourse.processing.org/t/posenet-with-p5js/21009/3 "2020-05-18T10:18:35Z")

</div>

thank you for the fast reply i will try it rn

---

<div class="post-metadata">

**Author:** ![babyP5](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/babyp5/32/9257_2.png) [@babyP5](https://discourse.processing.org/u/babyP5)\
**Post date:** [May 18, 2020, 10:45am UTC](https://discourse.processing.org/t/posenet-with-p5js/21009/4 "2020-05-18T10:45:46Z")

</div>

sorry its not working maybe if i remove the part where the inserted var is equal to false again but that way i can’t add any other number inside the array

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [May 18, 2020, 6:02pm UTC](https://discourse.processing.org/t/posenet-with-p5js/21009/5 "2020-05-18T18:02:16Z")

</div>

Check this example, it works fine (it only adds one element when the mouse is on the upper part of the canvas) :

```auto
var inserted = false;
var array = [];

function setup() {
  createCanvas(400, 400);
  noStroke();
}

function draw() {
  background(220);
  
  fill(255, 0, 0);
  rect(0, 0, width, height/2);
  
  fill(255);
  rect(0, height/2, width, height/2);
  
  text("inserted : " + inserted, 50, 50);
  
  text("array : [" + array + "]", 50, 100);
  
  if(mouseY < height/2){
  // If you didn't already inserted a number
    if(!inserted){
      array.push(floor(random(10)));
      inserted = true;
    }
  }else{ //Otherwise set inserted to false
      inserted = false;
  }
}

```

---

<div class="post-metadata">

**Author:** ![babyP5](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/babyp5/32/9257_2.png) [@babyP5](https://discourse.processing.org/u/babyP5)\
**Post date:** [May 20, 2020, 12:29pm UTC](https://discourse.processing.org/t/posenet-with-p5js/21009/6 "2020-05-20T12:29:25Z")

</div>

thank you so much worked like charm
