The calls to analogWrite() are not necessary for switching on or off only. They will also override your commands since they are called inside the loop() function.
You may find it easier to send bytes [or characters if using Serial.print()] from Processing instead of writing an integer.
An ‘int’ is made of four bytes and can break the sequence on the Arduino side.
Personally, I would use (and have used) characters for sending commands this way.
As an example, for an ON command you could use
Serial.print('A');
and for OFF
Serial.print('a');
This would give control over 26 pins or options without much effort.
Arduino side:
if (Serial.available() >= 1){
rx = Serial.read();
// If you have many options then a case structure
// would be better here
if ('A' == rx){
digitalWrite(LED1, HIGH);
}else if ('a' == rx){
digitalWrite(LED1, LOW);
}
...