Go Down

Topic: Drawing Lines In Processing Using Potentiometers (Read 1 time) previous topic - next topic

DaveyReilly

I'm trying to use serial communication to use two potentiometers and a button to make an Etch-A-Sketch programme, with the potentiometers controlling the X and Y points of the line and the button to clear the canvas.
I can make a drawing programme in Processing with the mouse controlling the line and have also managed to write one that displays the value of the potentiometers. However, I'm really don't know how to map the X and Y values to the potValue from the Arduino sketch. Could somebody provide some guidance please?

PaulS

How are you sending the values to the Processing application? How are you reading the values in Processing?

Getting the 2 values into Processing is not a difficult task. Using the values as x and y should be trivial.


PaulS

That code changes the background color of the Processing window, based on the settings of three potentiometers that are connected to the Arduino.

In your case, the Arduino code would look the same, except the variable names would be different, and there would only be two values sent.

The Processing code would look nothing like that code, except for the serialEvent() method. Even that would require changes, to read only two values and store the values in variables with meaningful names. (I can't see drawing a line to (redValue, greenValue)).

DaveyReilly

Would I not need to send a boolean as well as the potentiometer values for the button's state?

It's the serialEvent() method that has me stumped.

My draw() method is as follows:
Code: [Select]
void draw() {
float targetX = posX;
posX += (targetX - x) * easing;
float targetY = posY;
posY += (targetY - posY) * easing;
//float weight = dist(x, y, px, py);
//strokeWeight(weight);
line(posX, posY, prevX, prevY);
prevY = posY;
prevX = posX;
}


I've based posX/Y and prevX/Y on a working example using mouseX/Y and pmouseX/Y, I just don't know how to map those values to the potentiometer values in the serialEvent() method.

Go Up