NullPointerException eror
in
Core Library Questions
•
2 years ago
import processing.serial.*;
public static boolean isOnline = false;
Serial myPort; // Create object from Serial class
int val; // Data received from the serial port
void setup()
{
size(200, 200);
// I know that the first port in the serial list on my mac
// is always my FTDI adaptor, so I open Serial.list()[0].
// On Windows machines, this generally opens COM1.
// Open whatever port is the one you're using.
//
try {
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
myPort.clear();
isOnline = true;
}
catch(Exception e) {
System.out.println("no hardware connected.");
}
}
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 == 3) { // If the serial value is 2,
fill(0); // set fill to black
} else if (val == 1) {
fill (204);
} else {
fill (204, 102, 0);
} rect(50, 50, 100, 100);
}
public static boolean isOnline = false;
Serial myPort; // Create object from Serial class
int val; // Data received from the serial port
void setup()
{
size(200, 200);
// I know that the first port in the serial list on my mac
// is always my FTDI adaptor, so I open Serial.list()[0].
// On Windows machines, this generally opens COM1.
// Open whatever port is the one you're using.
//
try {
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
myPort.clear();
isOnline = true;
}
catch(Exception e) {
System.out.println("no hardware connected.");
}
}
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 == 3) { // If the serial value is 2,
fill(0); // set fill to black
} else if (val == 1) {
fill (204);
} else {
fill (204, 102, 0);
} rect(50, 50, 100, 100);
}
1