hi, first, I'm french so please don't takke a look at my faults ![]()
I'm working on a projects with an Arduino Uno :
I read the tension in Analog 3 ans if it's more than 2500 mV, i put a 1 else, i put a 0.
Here is my program :
//variable stockant la valeur lue sur le CAN
int valeurLue;
int i;
char motInter[] = "0000";
String motRecu ;
String motFinal ;
char test_depart[] = "1111";
char test_fin[] = "0000";
//résultat stockant la conversion de valeurLue en Volts
float tension;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
Serial.println("Attente");
Serial.println(test_depart);
}
void loop()
{
//boucle tant que l'émission n'a pas démarrée
while (strncmp(motInter,test_depart,4) != 0) {
Serial.println("Attente");
Serial.println(strncmp(motInter,test_depart,4));
//On reinitialise le mot intermediaire
char motInter[] = "1111";
char test_depart[] = "1111";
//Pour le capter à nouveau
for (i=0; i<4; i++) {
delay (1000);
valeurLue = analogRead(3);
//Serial.println(valeurLue);
tension = valeurLue * 4.88;
//Serial.println(tension);
if (tension < 2500) {
motInter[i] = '0';
}
Serial.println(motInter);
}
}
String motRecu = String(motInter);
//Une fois que l'émission a commencé on attend la fin
while (strcmp(motInter,test_fin) != 0) {
Serial.println("emission en cours");
char motInter[] = "0000";
for (i=0; i<4; i++) {
delay(2000);
valeurLue = analogRead(3);
//Serial.println(valeurLue);
tension = valeurLue * 4.88;
//Serial.println(tension);
if (tension > 2500) {
motInter[i] = '1';
}
}
motRecu.concat(motInter);
}
Serial.println("FIN");
Serial.println(motRecu);
motFinal = motRecu.substring(4 , motRecu.length()-4);
Serial.println(motFinal);
//on ne fait plus rien
while(true){
Serial.println("rien");
}
}
So the problem is in the first while loop : it's never go out of it even if motInter = "1111" !
But if i initialize it as "1111" directly, it don't go inside the while loop.
I don't understand what's the problem, maybe i don't understand how arduino change a char type variable.
Thanks for you help !