Convert an array sketch from Processing to Arduino?

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
}

I'm confused about your gig and the user experience.

How and where would the user draw something for the Arduino to interpret as a line? In processing you draw this with the mouse on your computer screen — there is no such a thing with the Arduino.

Thanks for the reply; I may have simplified my explanation too much as this is a complicated project to explain. It is part game, part interactive art project. A user draws a shape with a pen on an XY pen-plotter and that shape is recorded by encoders attached to each axis. The computer then replicates the shape, or otherwise interacts with the shape, through stepper motors also on each axis. Right now my computer is a Raspberry Pi which controls the stepper motors through an Arduino. I used Processing on the Pi so that I could use the computer mouse to simulate the physical stylus as I was writing the code and designing this whole contraption. The screen and mouse were only used for testing purposes. Now that this all works in a physical form, the screen is no longer necessary. I would like to eliminate the Pi to reduce complexity and cost. I know the Arduino can handle all the computational aspects, I'm just not sure how. Unfortunately, the physical size of this plotter may end up being quite large, 9ft x 9ft, which results in a huge array when recording encoder data over that area. The Pi handles it fine, but maybe the Arduino won't have enough memory.

How many points in each direction does the array have and what range of values are held in each cell of the array ?

is there a need to capture/store many points in an array? why not drive the motors as the input is received?

so you have a large 2D contraption that lets you move a head attached to the X and Y motors and you want to record the movement ? The memory size will be directly a function of the sampling precision for that movement

Thank you all for your replies, I think I am going to stick with the RPi that I have working.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.