I created a sketch in Processing that lets me draw a line on the screen that a circle "ball" bounces off of. This let me successfully create a project with a Raspberry Pi and an Arduino that is basically Pong - A user draws a line with a physical stylus on a board whose location is recorded in the Processing sketch as an array line. Then the location of the moving ball from the sketch is transferred to stepper motors to control a physical ball on an XY plotter. This works okay, but I would like to remove the Raspberry Pi from the build as it is overkill. I imagine it is possible to create the same array in Arduino that Processing on the Pi is creating visually, but I don't have the vocabulary to search for what I want properly.
I am unsure how to record the array drawn and have Arduino check for when that line is reached by the ball. I think some XY Plotter or G-Code examples are close to what I want but they have so many other features that I get lost trying to figure out what is needed or not.
Here is a simple example sketch for Processing that shows what I'm doing. The circle travels across the board until it bounces off a line drawn by the user. The circle can also be moved anywhere on the board by simply clicking.
Thank you for any assistance.
PGraphics pg; //load graphics feature
int ellipseX = 0; //coordinates for the drawn circle
int ellipseY = 0;
int diameter = 50; //Desired circle size
int direction = 1; //This gets multiplied by -1 in code. Positive moves right, negative moves left
void setup() {
size(650, 650); //Displayed window size. P2D helps graphics load faster for more accurate clicks.
pg = createGraphics(width, height); //creates a new virtual image in graphic buffer, initially set to the same size as the display window. This will change once the work area is defined.
}
void mouseClicked(){ //When the mouse is clicked...
ellipseX = mouseX; //..set the coordinates of the circle to match the location of the mouse
ellipseY = mouseY;
}
void draw() { //start the drawing loop
frameRate(60); //set the drawing refresh rate
background(255); //set background color. 0 is black, 225 is white
pg.beginDraw(); //start the graphics drawing context
pg.stroke(0); //Animated line color is black
pg.strokeWeight(1); //Animated line width
if (mousePressed == true) { //If mouse button is held down...
pg.line(mouseX, mouseY, pmouseX, pmouseY);// ...draw a continuous line that follows the cursor
}
ellipse(ellipseX, ellipseY, diameter, diameter); //draw the circle at the location clicked and of the size specified
createShape(ELLIPSE, ellipseX, ellipseY, diameter, diameter); //now draw that same circle into the graphics context
ellipseX = ellipseX + direction; //Once each frame, move the circle over one unit. If direction is positive the circle goes right; if negative, left
color c = pg.get((ellipseX + (diameter/4)*direction), ellipseY); //Check the color of the pixel 1/4diameter either ahead of or behind the currect location
if (c < 0 ) { //If the pixel ahead is dark, i.e. ta line is approaching...
ellipseY = ellipseY + (diameter/2);//move the circle down half the diameter of the circle...
direction = direction * -1; // and flip the direction of travel
}
pg.endDraw(); //end the graphics context
image(pg, 0, 0); //display the completed image for this frame
}