There is an icon, just above the smiley faces, with # on it. That icon should be clicked before posting code. "Why?", you ask. Does your code really look like this:
images = loadImage( "picture" + i + ".png" );
I hope not.
val = analogRead(A5);
val = map(val, 30, 600, 0, 510);
You read an actual value, map that to the range 0 to 510, then read another value and send that one. So, what is the map() doing for you?
In your Processing sketch, you need to do several things.
Import the serial library:
Define an instance of the serial library:
Initialize the instance and tell the serial object to buffer data until something interesting happens (in setup()):
myPort = new Serial(this, Serial.list(), 2400);
// tell the serial port not to generate a serialEvent
//until a linefeed is received:
You can print the list of COM ports that Processing knows about:
so that you can use the correct index - 2 in my case, but it may not be in your case.
add a serialEvent() method.
void serialEvent(Serial myPort)
// Read the serial data
String myString = myPort.readStringUntil('\n');
The Arduino code uses Serial.println(), so the value is followed by the carriage return. Processing will buffer data until the carriage return arrives. When it does, it will fire the serialEvent callback.
In that callback, you read the value as a String. Then, you need to convert the value in the String object to an integer, and store the integer in a global variable.
In the draw() function, quit iterating through the images. Instead, draw just the one image whose index is stored in the global variable. To reduce flicker, keep another (global) variable that contains the last image index, and do not redraw if the previous and current index is the same.