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() > 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 < 16 ; i ++) {
// Serial.print(lights[i]);
// }
// Serial.println("");
// newValue = false;
}
if (counter > 15) {
counter = 0;
Serial.print("\n");
}
if (incomingValues == 1) {
digitalWrite(13, HIGH);
} else if (incomingValues == 0) {
digitalWrite(13, LOW);
}
}