Hi, can anyone tell me where I'm wrong?
I need to read hexadecimal strings from the serial. I'm using this program as a test, using the "strcmp" instruction. The program seems to work up to the 3 byte check, while it seems that it does not do any kind of control from 4 bytes onwards
#include <string.h>
byte variable[11];
byte index = 0;
byte flag = 0;
byte coderead1 [] = {0x7E, 0x09, 0x00, 0x03, 0x01, 0x73, 0x41, 0x00, 0x18, 0xD7, 0xA7};
byte coderead2 [] = {0x7E, 0x09, 0x00, 0x03, 0x01, 0x73, 0x01, 0x00, 0x18, 0x97, 0x27};
//===================================
//= SETUP =
//===================================
void setup() {
Serial.begin(9600);
delay(2000);
Serial.println("-----START----");
pinMode(3, OUTPUT);
pinMode(2, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
flag =0;
} //
//===================================
//= LOOP =
//===================================
void loop() {
digitalWrite(3, LOW);
while (Serial.available() > 0)
{
byte b = Serial.read();
variable[index++] = b;
}
if (index == 11)
{
index = 0;
if (strcmp(coderead1, variable) == 0)
{
Serial.print("Corretto !!!!!");
Serial.println();
digitalWrite(2, HIGH);
delay(1000);
digitalWrite(2, LOW);
}
else
{
Serial.print("ERRATO");
Serial.println();
}
}
}