I posted a
threadearlier to help me get started on this, and got some help. Now, I have made some headway. I can now get the "joystick" to snap back to the midpoint of the umbrella image. Now the tricky part is going to be getting the xVal and yVal to output "good" data through the serial port to the servos.
Furthermore, there will be a laser attached to the pan & tilt, which will point at an object on a wall. When it reaches said object, the program will display a different main image and a list image with selectable options for right and wrong answers.
Any advice would be helpful...
Here's what I have so far:
int ellipseSize = 70;
int screenXSize = 1920;
int screenYSize = 1080;
int midUmbrellaX = 1750;
int midUmbrellaY = 910;
int xVal = 0;
int yVal = 0;
PImage umbrella;
PImage selection;
PImage stars;
PImage spectrum;
PImage spectra;
int value = 0;
void setup() {
size(screenXSize, screenYSize);
frame.removeNotify();
frame.setUndecorated(true);
umbrella = loadImage("Umbrella_Corporation_logo.jpg"); // Load the image into the program
selection = loadImage("Grocery-List.jpg");
stars = loadImage("absorptionspec.jpg");
spectrum = loadImage("types_of_spectra.jpg");
spectra = loadImage("spectra.jpg ");
}- void draw() {
frame.setLocation(0, 0);
noCursor();
stroke(0);
strokeWeight(40);
line(0, 0, 1920, 0);
line(0, 0, 0, 1080);
line(1920, 0, 1920, 1080);
line(0, 1080, 1920, 1080);
image(umbrella, 1600, 760);
image(selection, 1600, 20);
image(stars, 20, 20);
fill(0, 64, 255, 127);
float mx = constrain(mouseX, 1600 + (ellipseSize/2), 1900 - (ellipseSize/2));
float my = constrain(mouseY, 760 + (ellipseSize/2), 1060 - (ellipseSize/2));
smooth();
ellipseMode(CENTER); - if (mousePressed) {
if (mouseX < midUmbrellaX && mouseX >= 1600 && xVal > -1500) {
xVal = xVal - 1;
println(mouseX-midUmbrellaX);
println(midUmbrellaY-mouseY);
print("x= ");
println(xVal);
} - if (mouseX > midUmbrellaX && mouseX <= 1900 && xVal < 1500) {
xVal = xVal + 1;
println(mouseX-midUmbrellaX);
println(midUmbrellaY-mouseY);
print("x= ");
println(xVal);
} - if (mouseY < midUmbrellaY && mouseY >= 760 && yVal < 1500) {
yVal = yVal + 1;
println(mouseX-midUmbrellaX);
println(midUmbrellaY-mouseY);
print("y= ");
println(yVal);
}
if (mouseY > midUmbrellaY && mouseY <= 1060 && yVal > -1500) {
yVal = yVal - 1;
println(mouseX-midUmbrellaX);
println(midUmbrellaY-mouseY);
print("y= ");
println(yVal);
}
} - if (mousePressed == false) {
strokeWeight(1);
ellipse(midUmbrellaX, midUmbrellaY, ellipseSize, ellipseSize);
xVal = 0;
yVal = 0;
}
else if (mousePressed == true) {
strokeWeight(1);
ellipse(mx, my, ellipseSize, ellipseSize);
}
if (xVal >= 25 && xVal <= 100 && yVal >= 25 && yVal <= 100) {
image(spectrum, 20, 20);
image(spectra, 1600, 20);
}
}
1