# Using Processing to create a visual numeric keyboard for Arduino

**URL:** <https://discourse.processing.org/t/using-processing-to-create-a-visual-numeric-keyboard-for-arduino/32060>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [September 2, 2021, 11:32am UTC](https://discourse.processing.org/t/using-processing-to-create-a-visual-numeric-keyboard-for-arduino/32060 "2021-09-02T11:32:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Norac](https://avatars.discourse-cdn.com/v4/letter/n/e47c2d/32.png) [@Norac](https://discourse.processing.org/u/Norac)\
**Post date:** [September 2, 2021, 11:32am UTC](https://discourse.processing.org/t/using-processing-to-create-a-visual-numeric-keyboard-for-arduino/32060/1 "2021-09-02T11:32:01Z")

</div>

I create a code to use the Processing interface as a numeric Keyboard for my arduino Mega. It works just fine i keep becoming this warning. can somebody tell me what i did wrong? 🤨

```auto
import controlP5.*;
import processing.serial.*;

Serial port;

ControlP5 cp5;
int rectxSize = 80;
int rectySize = 80;
boolean rectOver1 = false;
boolean rectOver2 = false;
boolean rectOver3 = false;
boolean rectOver4 = false;
boolean rectOver5 = false;
boolean rectOver6 = false;
boolean rectOver7 = false;
boolean rectOver8 = false;
boolean rectOver9 = false;
boolean rectOver0 = false;

PFont font;

void setup() {
  size (940, 780);
  printArray(Serial.list());
  port =new Serial(this, "COM6",9600);

  cp5 = new ControlP5(this);
  font = createFont("calibri light", 20);
}

void draw() {
  background(204, 102, 0);
  fill(0, 255, 0);
  textFont(font);
  //text("Motor Control", 100, 30);

  update(mouseX, mouseY);

  rect(50, 50, rectxSize, rectySize);
  cp5.addButton("7")
    .setPosition(50, 50)
    .setSize(rectxSize, rectySize);

  rect(150, 50, rectxSize, rectySize);
  cp5.addButton("8")
    .setPosition(150, 50)
    .setSize(rectxSize, rectySize);

  rect(250, 50, rectxSize, rectySize);
  cp5.addButton("9")
    .setPosition(250, 50)
    .setSize(rectxSize, rectySize);

  rect(50, 150, rectxSize, rectySize);
  cp5.addButton("4")
    .setPosition(50, 150)
    .setSize(rectxSize, rectySize);

  rect(150, 150, rectxSize, rectySize);
  cp5.addButton("5")
    .setPosition(150, 150)
    .setSize(rectxSize, rectySize);

  rect(250, 150, rectxSize, rectySize);
  cp5.addButton("6")
    .setPosition(250, 150)
    .setSize(rectxSize, rectySize);

  rect(50, 250, rectxSize, rectySize);
  cp5.addButton("1")
    .setPosition(50, 250)
    .setSize(rectxSize, rectySize);

  rect(150, 250, rectxSize, rectySize);
  cp5.addButton("2")
    .setPosition(150, 250)
    .setSize(rectxSize, rectySize);

  rect(250, 250, rectxSize, rectySize);
  cp5.addButton("3")
    .setPosition(250, 250)
    .setSize(rectxSize, rectySize);

  rect(50, 350, rectxSize, rectySize);
  cp5.addButton("0")
    .setPosition(50, 350)
    .setSize(rectxSize, rectySize);
}

void update(int x, int y) {

  if ( overRect1(50, 250, rectxSize, rectySize) ) {
    rectOver1 = true;
  } else {
    rectOver1 = false;
  }

  if ( overRect2(150, 250, rectxSize, rectySize) ) {
    rectOver2 = true;
  } else {
    rectOver2 = false;
  }

  if ( overRect3(250, 250, rectxSize, rectySize) ) {
    rectOver3 = true;
  } else {
    rectOver3 = false;
  }

  if ( overRect4(50, 150, rectxSize, rectySize) ) {
    rectOver4 = true;
  } else {
    rectOver4 = false;
  }

  if ( overRect5(150, 150, rectxSize, rectySize) ) {
    rectOver5 = true;
  } else {
    rectOver5 = false;
  }

  if ( overRect6(250, 150, rectxSize, rectySize) ) {
    rectOver6 = true;
  } else {
    rectOver6 = false;
  }

  if ( overRect7(50, 50, rectxSize, rectySize) ) {
    rectOver7 = true;
  } else {
    rectOver7 = false;
  }

  if ( overRect8(150, 50, rectxSize, rectySize) ) {
    rectOver8 = true;
  } else {
    rectOver8 = false;
  }

  if ( overRect9(250, 50, rectxSize, rectySize) ) {
    rectOver9 = true;
  } else {
    rectOver9 = false;
  }

  if ( overRect0(50, 350, rectxSize, rectySize) ) {
    rectOver0 = true;
  } else {
    rectOver0 = false;
  }
}

void mousePressed() {
  if (rectOver1) {
    port.write('1');
  }
  if (rectOver2) {
    port.write('2');
  }

  if (rectOver3) {
    port.write('3');
  }

  if (rectOver4) {
    port.write('4');
  }

  if (rectOver5) {
    port.write('5');
  }

  if (rectOver6) {
    port.write('6');
  }

  if (rectOver7) {
    port.write('7');
  }

  if (rectOver8) {
    port.write('8');
  }

  if (rectOver9) {
    port.write('9');
  }

  if (rectOver0) {
    port.write('0');
  }
}

boolean overRect1(int x, int y, int width, int height) {
  if (mouseX >= x && mouseX <= x+width &&
    mouseY >= y && mouseY <= y+height) {
    return true;
  } else {
    return false;
  }
}

boolean overRect2(int x, int y, int width, int height) {
  if (mouseX >= x && mouseX <= x+width &&
    mouseY >= y && mouseY <= y+height) {
    return true;
  } else {
    return false;
  }
}

boolean overRect3(int x, int y, int width, int height) {
  if (mouseX >= x && mouseX <= x+width &&
    mouseY >= y && mouseY <= y+height) {
    return true;
  } else {
    return false;
  }
}

boolean overRect4(int x, int y, int width, int height) {
  if (mouseX >= x && mouseX <= x+width &&
    mouseY >= y && mouseY <= y+height) {
    return true;
  } else {
    return false;
  }
}

boolean overRect5(int x, int y, int width, int height) {
  if (mouseX >= x && mouseX <= x+width &&
    mouseY >= y && mouseY <= y+height) {
    return true;
  } else {
    return false;
  }
}

boolean overRect6(int x, int y, int width, int height) {
  if (mouseX >= x && mouseX <= x+width &&
    mouseY >= y && mouseY <= y+height) {
    return true;
  } else {
    return false;
  }
}

boolean overRect7(int x, int y, int width, int height) {
  if (mouseX >= x && mouseX <= x+width &&
    mouseY >= y && mouseY <= y+height) {
    return true;
  } else {
    return false;
  }
}

boolean overRect8(int x, int y, int width, int height) {
  if (mouseX >= x && mouseX <= x+width &&
    mouseY >= y && mouseY <= y+height) {
    return true;
  } else {
    return false;
  }
}

boolean overRect9(int x, int y, int width, int height) {
  if (mouseX >= x && mouseX <= x+width &&
    mouseY >= y && mouseY <= y+height) {
    return true;
  } else {
    return false;
  }
}

boolean overRect0(int x, int y, int width, int height) {
  if (mouseX >= x && mouseX <= x+width &&
    mouseY >= y && mouseY <= y+height) {
    return true;
  } else {
    return false;
  }
}

```

 ![Error](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/2/2e15104f61079ccf461d871d2afca8d5965ea820.png)

---

<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:** [September 2, 2021, 4:12pm UTC](https://discourse.processing.org/t/using-processing-to-create-a-visual-numeric-keyboard-for-arduino/32060/2 "2021-09-02T16:12:26Z")

</div>

Hello,

Add the buttons in [setup()](https://processing.org/reference/setup_.html) which runs once.

I did this and get no errors.

`:)`

---

<div class="post-metadata">

**Author:** ![Norac](https://avatars.discourse-cdn.com/v4/letter/n/e47c2d/32.png) [@Norac](https://discourse.processing.org/u/Norac)\
**Post date:** [September 2, 2021, 5:01pm UTC](https://discourse.processing.org/t/using-processing-to-create-a-visual-numeric-keyboard-for-arduino/32060/3 "2021-09-02T17:01:35Z")

</div>

Thank you so much it works perfectly
