How to create an array from serial.read? I'm working on a audio-reactive lightinstallation with 16 LED lights.
In Max MSP I analyse my audio and split the frequencies in 16 'parts'.
I store these parts in a message of 16 ints, either 1 or 0 (on of off).
Every time a new frequency is detected the message updates and puts out a new int from 16 numbers (for exampe 1000100100110101).

I receive this number in my serial monitor of my Arduino Uno.
I want to put this 'incomingValues' in an array so I can check if a number/frequency is 0 or 1. When it's 1 I can turn on my relay/ light.
The 'incomingValues' is changing quite quickly but that shouldn't be a problem right?

I tried multiple things to create an array and update this every time a new serial message is coming in but I'm not used to work with Arduino so I could need some help.

Thanks! :)

Here is my code:

int counter;
int incomingValues = 0;
int lights[16];


void setup() {
  Serial.begin(9600);
  counter = 0;
  pinMode(13, OUTPUT);
}

void loop() {

  boolean newValue = false;

  while (Serial.available() &gt; 0) {

    incomingValues = Serial.read();
    Serial.print(incomingValues);
    counter = counter + 1;

    newValue = true;
  }


  if (newValue) {
//    delay(50);
//    lights[counter] = incomingValues;
//
//
//    Serial.print(lights[0]);
//
//    for (int i = 0 ; i &lt; 16 ; i ++) {
//      Serial.print(lights[i]);
//    }
//    Serial.println("");
//    newValue = false;
  }

  if (counter &gt; 15) {
    counter = 0;
    Serial.print("\n");
  }

  if (incomingValues == 1) {
    digitalWrite(13, HIGH);
  } else if (incomingValues == 0) {
    digitalWrite(13, LOW);
  }
}
If you are able to send the message as 16 chars, followed by a newline, then here is a test sketch that might work for you. Use the Serial Monitor to send the 1000100100110101 data. Please ensure you have the Serial Monitor set to send a Newline Only.


// Valid input data from serial is 16 chars followed by a newline.
// 1000100100110101
const byte bufferSize = 17;
char inputBuffer[bufferSize + 1];

void setup(){
  Serial.begin(9600);
}

void loop(){

  if(Serial.available() &gt; 0){
    byte bytesRead = Serial.readBytesUntil('\n', inputBuffer, bufferSize);
    if(bytesRead == 16){
      for(byte i = 0; i &lt; 16; i++){
        if(inputBuffer[i] == '1'){
          Serial.print("on ");
        }
        else{
          Serial.print("off ");
        }
      }
      Serial.println();
    }
    else{
      Serial.println("Invalid data length.");
    }
  }
}