ARduino + C#

Hi, I’m using C# to send values to my arduino such as 12 and 24 to my arduino. I’ve got the coding were my arduino reads 12 if i send <12> from C# and when i send * an infinte for loop is activated. Now I got the infinite for loop to go from 0 to 15 and start again from 0 to 15 and this will keep on going until the arduino is switched on.

my infite for loop
for (int b = 0; b<17; b++)
{
look what is the value of serialValue
and do something
}
I did this infinite for loop because i’m storing the C# values on the ardunio, which are then stored in an array called serialValues__, and when i send * from C# the infinte loop starts.__
As explaind i want the arduino to go through all the values it received and if it receives 12 and pin 10 is high then pin 12 is high etc…
the problem i’m facing is that when the infite loop starts again from 0 and the value 12 reappeard from the array and pin 10 is low, pin 12 remains high and i want it to go LOW. And when b starts from 0 again and pin 10 is high i want pin12 u go high again
HERE is my coding I would appreciate any help cause i’m a college student and i need to solve this problme ASAP
char inData[10];
int index;
boolean started = false;
boolean ended = false;
boolean final = false;
int serialValues[16];
int serialIndex = 0;
const int Pin13 = 13;
const int Pin12 = 12;
const int Pin11 = 11;
const int Pin10 = 10;
int buttonState1 = 0;
int buttonState2 = 0;
** void setup()**
** {**
** //Serial1.begin(9600);**
** Serial.begin(9600);**
** //setting pinouts**
** pinMode(Pin13, OUTPUT);**
** pinMode(Pin12, OUTPUT);**
** pinMode(Pin11, INPUT);**
** pinMode(Pin10, INPUT);**
** }**
** void loop()**
** {**
** buttonState1 = digitalRead(Pin11);**
** buttonState2 = digitalRead(Pin10);**

** while(Serial.available() > 0)**
** {**
** char aChar = Serial.read();**
** if(aChar == ‘<’)**
** {**
** started = true;**
** index = 0;**
** inData[index] = ‘\0’;**
** }**
** else if(aChar == ‘>’)**
** {**
** ended = true;**
** }**

** else if(started)**
** {**
** inData[index] = aChar;**
** index++;**
** inData[index] = ‘\0’; **
** }**

__ else if (aChar ==’*’)__
** {**
** final = true;**
** }**
** }**

** if(started && ended)**
** {**
** // Convert the string to an integer**
** int inInt = atoi(inData);**
** Serial.println(inInt);**
** // Use the value**
** serialValues [serialIndex] = inInt;**
** serialIndex++;**

** // Get ready for the next time**
** started = false;**
** ended = false;**
** index = 0;**
** inData[index] = ‘\0’; **
** }**

** if(final)**
** while(1)**
{
** // loop through the serialValues, and do something**
** for(int b=0; b <16;b++ )**
** {**

__ int nextVal = serialValues**;
//if serial value is 24 and pin10 is connected to 5V switch led12 on**
** if (nextVal == 24 && buttonState2 == HIGH)
{
digitalWrite(Pin12, HIGH);
}
//if serial value is 12 and pin11 is connected to 5V switch led13 on**
** if (nextVal == 12 && buttonState2 == LOW)
{
digitalWrite(Pin12, LOW);
}
Serial.println(b);
delay(1000); **__

** }**
** }**
** }**

...and please don't cross-post.