Hi everybody,
i'm at my first experience with Arduino and i was thinking to try a program that light a specific led taking the number of the pin from serial.
Everything works until the digitalWrite, the leds are ok (i tried with the blink program and it works), the serial comunication is working too and i don't understand where the problem is, to me it seems all good my code...
A little explanation on how this program have to work: i want to send a message via serial monitor like A-1-2-A:
A = char that have to open and close the string, if none so i have an error
1 = command (1=HIGH) i don't have his part dont jet
2 = pin number that i want to light-up
Do you see the error in the code? the compiler says that all is good...
Thank you for your help and scuse me for my english mistakes
char inData[7];
char inChar;
byte index = 0;
int j,i;
char indirizzo;
int indirizzoInt;
void setup()
{
Serial.begin(115200);
pinMode(indirizzoInt, OUTPUT);
// pinMode(2, OUTPUT);
}
void loop()
{
while(Serial.available() > 0)
{
inChar = Serial.read();
inData[index] = inChar;
if(index==6)
{
for(i=0; i<index+1; i++)
{
Serial.print(inData[i]);
}
Serial.println();
if(inData[0]==inData[6])
{
Serial.println("OK1");
if(inData[0]=='A')
{
Serial.println("OK2");
}
else
Serial.println("KO2");
}
else
Serial.println("KO1");
indirizzo=inData[4];
indirizzoInt=atoi(&indirizzo);
Serial.print("indirizzo:");
Serial.println(indirizzoInt);
digitalWrite(indirizzoInt, HIGH);
}
index++;
inData[index] = '\0';
if(index>6){index=0;}
}
}