using Simple Read example, having problems.
in
Core Library Questions
•
2 years ago
I'm on a pc, and i'm using the simple read example from the serial library examples.
i have an arduino which is sending information from COM4 - not my choice just what the ftdi drivers do. I am
a beginner, so this is probably something really simple i'm doing wrong.
getting the error:
Error inside Serial.<init>()
HERE IS THE CODE
import processing.serial.*;
Serial myPort; // Create object from Serial class
int val; // Data received from the serial port
void setup()
{
size(200, 200);
String portName = Serial.list()[1];
myPort = new Serial(this, "COM4", 9600);
}
void draw()
{
if ( myPort.available() > 0) { // If data is available,
val = myPort.read(); // read it and store it in val
}
background(255); // Set background to white
if (val == 0) { // If the serial value is 0,
fill(0); // set fill to black
}
else { // If the serial value is not 0,
fill(204); // set fill to light gray
}
rect(50, 50, 100, 100);
}
1