Newbie question - Serial comunication
in
Integration and Hardware
•
1 year ago
Hi everyone.
I've an arduino that send the value of a potentiometer over serial and i want to use this code to visualize this data on the screen:
I've an arduino that send the value of a potentiometer over serial and i want to use this code to visualize this data on the screen:
- import processing.serial.*;
Serial port; // Create object from Serial class
float val; // Data received from the serial port
int x;
float easing = 0.05;
float easedVal;
void setup() {
size(440, 440);
frameRate(30);
smooth();
String arduinoPort = "COM5";
port = new Serial(this, arduinoPort, 9600);
background(0);
}
void draw() {
if ( port.available() > 0) { // If data is available,
val = port.read(); // read it and store it in val
val = map(val, 0, 255, 0, height); // Convert the values
}
float targetVal = val;
easedVal += (targetVal - easedVal) * easing;
stroke(0);
line(x, 0, x, height); // Black line
stroke(255);
line(x+1, 0, x+1, height); // White line
line(x, 220, x, val); // Raw value
line(x, 440, x, easedVal + 220); // Averaged value
x++;
if (x > width) {
x = 0;
}
}
Now, i've tested with this output by the arduino:
Now what am i doing wrong? Thx for the help!
But the output from processing is something like this:253
253
251
252
252
252
248
212
195
183
167
155
133
110
100
95
91
80
63
39
23
3
0
Now what am i doing wrong? Thx for the help!
1