Getting serial port data in to draw() function
in
Core Library Questions
•
1 year ago
Hi,
I'm trying to control a variable inside draw() with data from the serial port. The serial port is connected to an Arduino with a simple potentiometer circuit.
I can read in from the serial port to a variable called inByte. But then how do I work with that inside draw()? The code is below.
Any help would be greatly appreciated.
Thanks,
Shane
I'm trying to control a variable inside draw() with data from the serial port. The serial port is connected to an Arduino with a simple potentiometer circuit.
I can read in from the serial port to a variable called inByte. But then how do I work with that inside draw()? The code is below.
Any help would be greatly appreciated.
Thanks,
Shane
- import processing.serial.*;
Serial myPort; // The serial port
void setup () {
size(400, 300);
println(Serial.list());
myPort = new Serial(this, Serial.list()[0], 9600);
myPort.bufferUntil('\n');
}
void draw () { - fill(0, 12);
line(inByte, 0, width, height);
}
void serialEvent (Serial myPort) {
String inString = myPort.readStringUntil('\n');
if (inString != null) {
inString = trim(inString);
float inByte = float(inString);
inByte = map(inByte, 0, 1023, 0, 255);
}
}
1