Hi:
I have some nested if and an array comparison
if (readString == "ON1"){
if (SetRoutine ==0){
Contador++;
digitalWrite(LED1, HIGH);
Memoria[Contador] = 10;}
if (SetRoutine == 1){
Contador++;
digitalWrite(LED1, HIGH);
Comparador[Contador] = 10;
if(Memoria[1] == Comparador[1]){ <<<<<<=================HERE!!!!!!!!!!!!!!!!!!!
a = 5;}}}
For some reason unknown to me, the "HERE" portion is not working (5 is not being assigned to "a"). What could be wrong?
Thanks in advance!
What is that SPANGLISH ? Half in English and half in spanish )
Where's the rest of your code ?
(memoria=memory)
(contador=counter)
(comparador=comparator)
Add Serial.print of Contador, Memoria[1], and Comparador[1], see what values they actually are.
I'm not really surprised it's not working. Lets break down your snippet.
// Say Contador is set to zero (0) and readString == "ON1" and SetRoutine == 0.
if (readString == "ON1")
{
if (SetRoutine ==0)
{
Contador++; // Contador (0) + 1 = 1.
digitalWrite(LED1, HIGH);
Memoria[Contador] = 10; Memoria[ 1 ] = 10;
}
Now say readString == "ON1" again and SetRoutine == 1
if (SetRoutine == 1)
{
Contador++; (1) + 1 = 2
digitalWrite(LED1, HIGH);
Comparador[Contador] = 10; // Comparador[ 2 ] = 10;
if(Memoria[1] == Comparador[1]) // Memoria[ 1 ] = 10 and Comparador[ 1 ] = NULL
{
a = 5;
}
}
}
These two will never be equal unless you reset Contador back to zero or have your code like this "if(Memoria[1] == Comparador[2])" instead.