This day just keeps getting worse…
What am i doing wrong? ive been staring for the screen for hours.
I lost my project sketch and had to redo this whole part, i know for sure it was 99% the same code i used and it was working
Code:
void setup()
{
Serial.begin(9600);
}
void loop()
{
char string[10];
char comando[5];
char codigo[5];
char *index;
int charsRead;
while (true)
{
if (Serial.available() > 0)
{
charsRead = Serial.readBytesUntil('\n', string, sizeof(string) -1);
string[charsRead] = '\0';
Serial.print("string = ");
Serial.println(string);
index = strchr( string, ';');
*index = '\0';
strcpy(comando, string);
strcpy(codigo, index + 1);
Serial.print("comando = ");
Serial.println(comando);
Serial.print("codigo = ");
Serial.println(codigo);
break;
}
}
if (comando == "hello")
{
Serial.print("hello is the string");
}
else
{
Serial.print("hello isn't the string");
}
}
It reads a string i send, splits it in two parts, “comando” ( first half ) and “codigo” ( second half ). Everything’s fine until i try to do this simple IF statement.
IF comando = hello , print " hello is the string ", if its anything but hello, " hello isnt the string.
Thing is, when i send “hello”, it always prints “hello isn’t the string”, what am i doing wrong?
i’ve been working nonstop on visual basic for the past few days my head is hurting, im sure im missing something obvious…
Attachment below