Pages: [1]   Go Down
Author Topic: Drawing Lines In Processing Using Potentiometers  (Read 1443 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm trying to adapt this code: http://arduino.cc/en/Tutorial/VirtualColorMixer

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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)).
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Would I not need to send a boolean as well as the potentiometer values for the button's state?
Sure. I forgot about that requirement.

Quote
I just don't know how to map those values to the potentiometer values in the serialEvent() method.
I don't understand what mapping you are talking about. You are sending x and y (and adding the switch state) from the Arduino, as strings. The serialEvent class captures the string, and extracts the values as floats (why, when they are sent as ints, excapes me). Just assign those floats (or, better yet, ints) to posX and posY.

You may need to scale the data from the Arduino to match the screen size, but that is a simple matter.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That's what I'm having trouble with, assigning those floats.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
That's what I'm having trouble with, assigning those floats.
You're kidding, right?

Code:
float[] colors = float(split(inString, ","));
Is in the code you are deriving from. Presumably, you are using some name other than colors for your array, since your array contains "mouse locations". If we assume that your array is called mouseLocs,

Code:
posX = mouseLocs[0];
posY = mouseLocs[1];
Logged

Pages: [1]   Go Up
Jump to: