control a specified pin on arduino with processing

Could you please tell us a way we can specify which LED on the arduino pins will be turned on by processing? Our project will be a grid of lightboxes with LEDs which will function as a “screen” and will be controlled by processing. we have created a sample of the arduino & processing code to control 12 LEDs, and we are able to control them by sequence but the problem is that we don’t know which LED will light up first.

arduino code:

int ledPin = {1,2,3,4,5,6,7,8,9,10,11,12,13};
int procByte[13]; //incoming byte

void setup()
{
// initialize the serial communication:
Serial.begin(9600);
// initialize the ledPin as an output:
for (int i=0; i<13; i++) {
pinMode(ledPin*, OUTPUT);*

  • }*
    }
    void loop() {
  • // check if data has been sent from the computer:*
  • if (Serial.available()>13) {*
  • for (int i=0; i<13; i++) {*
  • // read each byte*
    _ procByte = Serial.read();_
    * // pass the value to each pin*
    analogWrite(ledPin_, procByte*);
    }
    }
    }
    processing code_

    _import processing.serial.;
    Serial port;
    void setup() {
    * size(500, 150);
    port = new Serial(this, “COM15”, 9600);
    background(255);
    stroke (0);
    line (250, 0, 250, 150);
    }
    void draw() {
    if (mouseX <250 ) {
    port.write(255); //first (??) ledPin on
    port.write(0); //other ledPins off*

    * port.write(0);
    port.write(0);
    port.write(0);
    port.write(0);
    port.write(0);
    port.write(0);
    port.write(0);
    port.write(0);
    port.write(0);
    port.write(0);
    port.write(0);
    }
    else if (mouseX < 500 ) {
    port.write(0); //first(??) ledPin off*

    * port.write(255); //this led on*
    * port.write(0);
    port.write(0);
    port.write(0);
    port.write(255);
    port.write(0);
    port.write(0);
    port.write(0);
    port.write(0);
    port.write(0);
    port.write(0);
    port.write(0);
    }
    }*_

There are several problems with the Arduino code, and at least one with the Processing code.

There are 13 pins defined for LEDs - 1 through 13. Then, you use pin 0 and 1 for serial communication. You can't (effectively) control an LED on pin 1.

You have an array set up to hold the received data, but there is no reason to save the data after it is used to turn an LED on.

You send 13 bytes of data from the Processing program, but don't start reading until there are more than 13 bytes to read.

The analogWrite function is used to send data to the analog pins - none of which you are using. You should be using digitalWrite, instead.

For the non-PWM pins, you can only write HIGH or LOW to the pin, not a range of values between 0 and 255.

There is nothing in the stream of data that defines when one frame ends and the next one begins.

In the Processing code, you write one set of bytes if the mouse is at less than 250 in X, and another set if the mouse is at less than 500. What does the position of the mouse have to do with the original problem statement?

Would you please make another attempt to explain what you are trying to do?

The analogWrite function is used to send data to the analog pins

The analogWrite function is used to write PWM values to PWM (digital) pins.