Using Processing to create a visual numeric keyboard for Arduino

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? :face_with_raised_eyebrow:

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;
  }
}

1 Like

Hello,

Add the buttons in setup() which runs once.

I did this and get no errors.

:)

1 Like

Thank you so much it works perfectly

1 Like