gui to send to arduino
in
Programming Questions
•
6 months ago
I have made the following code, click on num pad. I am trying to make all of those numbers clickable and then I want that to send the corresponding integer to an arduino program. Any help would be greatly appreciated. I have never worked with processing before. I know that the noLoop(); function is giving me problems but I am not sure what to do. I also need to make offense defense... clickable. Thanks!
PFont f; //Creates font
boolean overBox = false;
boolean locked = false;
boolean click0 = false;
boolean locked0 = false;
boolean clickoff = false;
boolean lockedoff = false;
float xOffset = 0.0;
float yOffset = 0.0;
boolean overBox = false;
boolean locked = false;
boolean click0 = false;
boolean locked0 = false;
boolean clickoff = false;
boolean lockedoff = false;
float xOffset = 0.0;
float yOffset = 0.0;
void setup () {
size(1000, 700); //Size of main screen
f = createFont("Arial", 16, true); //Function for font
}
size(1000, 700); //Size of main screen
f = createFont("Arial", 16, true); //Function for font
}
void draw() {
background(85, 86, 118);
fill(81, 149, 242); //Color of Offensive rectangle
rect(100, 75, 200, 120);
background(85, 86, 118);
fill(81, 149, 242); //Color of Offensive rectangle
rect(100, 75, 200, 120);
fill(81, 149, 242); //Color of Num Pad rectangle
rect(680, 500, 200, 120);
rect(680, 500, 200, 120);
fill(81, 149, 242); //Color of Defense rectangle
rect(680, 75, 200, 120);
rect(680, 75, 200, 120);
fill(81, 149, 242); //Color of Special Teams rectangle
rect(100, 500, 200, 120);
rect(100, 500, 200, 120);
fill(#7F8180); //Color of Exit rectangle
rect(420, 530, 150, 80);
rect(420, 530, 150, 80);
textFont(f, 30);
fill(#D3D3EA); //Color of "Offense" Font
text("Offense", 140, 140);
textFont(f, 30);
fill(#D3D3EA); //Color of "Defense" Font
text("Defense", 720, 140);
fill(#D3D3EA); //Color of "Defense" Font
text("Defense", 720, 140);
textFont(f, 25);
fill(#D3D3EA); //Color "Special Teams" Font
text("Special Teams", 115, 570);
fill(#D3D3EA); //Color "Special Teams" Font
text("Special Teams", 115, 570);
textFont(f, 30);
fill(#D3D3EA); //Color of "Num Pad" font
text("Num Pad", 710, 570);
fill(#D3D3EA); //Color of "Num Pad" font
text("Num Pad", 710, 570);
textFont(f, 30);
fill(#D3D3EA); //Color of "Exit" font
text("Exit", 465, 575);
fill(#D3D3EA); //Color of "Exit" font
text("Exit", 465, 575);
// Test if the cursor is over the box
if (mouseX > 680 && mouseX < 880 &&
mouseY > 500 && mouseY < 620) {
overBox = true;
if (!locked) {
stroke(255);
fill(153);
}
}
else {
stroke(153);
fill(153);
overBox = false;
}
// Test if the cursor is over the offense
if (mouseX > 320 && mouseX < 420 &&
mouseY > 480 && mouseY < 580) {
clickoff = true;
if (!lockedoff) {
stroke(255);
fill(153);
}
}
else {
stroke(153);
fill(153);
clickoff = false;
}
}
void mousePressed() {
if (overBox) {
locked = true;
fill(5, 86, 118); //Color of Offensive rectangle
rect(0, 0, 1000, 700);
fill(81, 149, 242);
rect(300, 70, 400, 530);
rect(300, 70, 400, 530);
fill(#FEFF3E);
rect(320, 480, 100, 100);
rect(320, 480, 100, 100);
fill(#FEFF3E);
rect(320, 350, 100, 100);
rect(320, 350, 100, 100);
fill(#FEFF3E);
rect(320, 220, 100, 100);
rect(320, 220, 100, 100);
fill(#FEFF3E);
rect(320, 90, 100, 100);
rect(320, 90, 100, 100);
fill(#FEFF3E);
rect(450, 480, 100, 100);
rect(450, 480, 100, 100);
fill(#FEFF3E);
rect(450, 350, 100, 100);
rect(450, 350, 100, 100);
fill(#FEFF3E);
rect(450, 220, 100, 100);
rect(450, 220, 100, 100);
fill(#FEFF3E);
rect(450, 90, 100, 100);
rect(450, 90, 100, 100);
fill(#FEFF3E);
rect(580, 480, 100, 100);
rect(580, 480, 100, 100);
fill(#FEFF3E);
rect(580, 350, 100, 100);
rect(580, 350, 100, 100);
fill(#FEFF3E);
rect(580, 220, 100, 100);
rect(580, 220, 100, 100);
fill(#FEFF3E);
rect(580, 90, 100, 100);
rect(580, 90, 100, 100);
textFont(f, 50);
fill(0);
text("0", 355, 550);
textFont(f, 50);
fill(0);
text("1", 355, 420);
textFont(f, 50);
fill(0);
text("4", 355, 290);
textFont(f, 50);
fill(0);
text("7", 355, 160);
textFont(f, 50);
fill(0);
text("2", 485, 420);
textFont(f, 50);
fill(0);
text("5", 485, 290);
textFont(f, 50);
fill(0);
text("8", 485, 160);
textFont(f, 50);
fill(0);
text("3", 615, 420);
textFont(f, 50);
fill(0);
text("6", 615, 290);
textFont(f, 50);
fill(0);
text("9", 615, 160);
}
else {
locked0 = false;
}
fill(0);
text("0", 355, 550);
textFont(f, 50);
fill(0);
text("1", 355, 420);
textFont(f, 50);
fill(0);
text("4", 355, 290);
textFont(f, 50);
fill(0);
text("7", 355, 160);
textFont(f, 50);
fill(0);
text("2", 485, 420);
textFont(f, 50);
fill(0);
text("5", 485, 290);
textFont(f, 50);
fill(0);
text("8", 485, 160);
textFont(f, 50);
fill(0);
text("3", 615, 420);
textFont(f, 50);
fill(0);
text("6", 615, 290);
textFont(f, 50);
fill(0);
text("9", 615, 160);
}
else {
locked0 = false;
}
// Test if the cursor is over the zero
if (mouseX > 320 && mouseX < 420 &&
mouseY > 480 && mouseY < 580) {
click0 = true;
if (!locked0) {
stroke(255);
fill(153);
}
}
else {
stroke(153);
fill(153);
click0 = false;
}
noLoop();
}
}
void mouseReleased() {
locked = false;
fill(5, 86, 118); //Color of Offensive rectangle
rect(0, 0, 1000, 700);
}
locked = false;
fill(5, 86, 118); //Color of Offensive rectangle
rect(0, 0, 1000, 700);
}
void mousePressed0() {
if (click0) {
locked0 = true;
fill(5, 86, 118); //Color of Offensive rectangle
rect(0, 0, 1000, 700);
if (click0) {
locked0 = true;
fill(5, 86, 118); //Color of Offensive rectangle
rect(0, 0, 1000, 700);
}
else {
locked0 = false;
}
noLoop();
}
else {
locked0 = false;
}
noLoop();
}
void mouseReleased0() {
locked0 = false;
fill(5, 86, 118); //Color of Offensive rectangle
rect(0, 0, 1000, 700);
}
locked0 = false;
fill(5, 86, 118); //Color of Offensive rectangle
rect(0, 0, 1000, 700);
}
1