int HYSTERESIS = 2;
By convention, all capital letters in the name are reserved for #define names.
sensVal = sensVal/10;
diff = abs(sensVal - previous); // calculating hysteresis
if (diff <= HYSTERESIS){
sensVal = previous;
}
previous = sensVal;
Serial.println(sensVal);
You could avoid all the floating point arithmetic, and simply have Processing do the divide by 10 part.
You should only send data if there is a difference. By not converting to a float, you could send the high order byte and low order byte, and have Processing re-assemble the integer value. Doing so would send just two bytes, instead of a minimum of 4 (x.xx) to a maximum of 7 (xxxx.xx).
Since the difference between 123 and 123.45 is going to be difficult to see when the value is divided by 1024/360 in Processing, anyway, I'd skip the floating point crap altogether. Just send, and receive, an int.
myPort = new Serial(this, "COM18", 9600);
Quit dragging your feet. Get the speed up to 115200.
void serialEvent(Serial myPort){
String val = myPort.readStringUntil('\n');
if(val != null){
angle = float(trim(val));
angle = map(angle,0,1024,0,360);
}
You've told Processing that the serialEvent() method should be called only when a carriage return arrives. Then, reading only a part of the serial data, even though it will be all of it, wastes resources. What is there to trim? The float() function will ignore leading white space, and stop reading at any non-numeric content in the string. Ergo, the trim() call is a waste of time.
Viewed neighbours cute daughter
Always a good diversion...
I seem to just overload Processing with data faster than it can handle.
I seriously doubt that. Printing the values received in Processing (and showing the output to us) might suggest a course of action that you have not considered, if the above suggestions do not pan out.