Hi,
Im doing a program that it has verify that the data of serial port put in from monitor serial are equal that an array of chars definite in program.
Program:
char inChar;
char inputString[256];
char prueba[] = "abc";
int i = 0;
void setup() {
Serial.begin(9600);
}void loop() {
while (Serial.available()) {
inChar = (char)Serial.read();
inputString = inChar;
- i++;*
- if (inChar == '\r') {*
_ inputString ='\0';_
* i=0;*
* Serial.println(inputString);*
* Serial.println(prueba);*
* Serial.println(strcmp(inputString, prueba));*
* }*}
}[/quote]
Result:
> dfg
>
> abc
> 3
>
> abc
>
> abc
> -87
>
> ghdags
>
> abc
> -87
>
> dfgsgsd
>
> abc
> -87
>
> s<s
>
> abc
> -87
>
> f<
>
> abc
> -87
>
> f<s<fsfsdsgds
>
> abc
> -87
If the first serial data is 'abc':
> abc
>
> abc
> 13
>
> fdsfsd
>
> abc
> -87
>
> dhsdgds
>
> abc
> -87
>
> dfgdgds
>
> abc
> -87
What is the problem?
Help me please,
Regards