Hi, I'm doing a small project and can not find the solution to the following problem: when I read the serial numbers 1,0,2,4 on the go to convert 1024 turns to 24, but when the numbers are 1,1,2,4, then it works correctly and converts to 1124.
Someone we could help me please?
#include <LiquidCrystal.h>
#include <stdio.h>
#include <stdlib.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
char buffer2[5];
char a = ' ';
int state = 0;
int contador = 0;
int contador_errors = 0;
char buffer[500] = {' '};
int h = 0;
void setup()
{
Serial.begin(19200);
Serial3.begin(19200);
lcd.begin(16, 2);
}
void loop()
{
while (state == 0)
{
if(contador_errors > 5)
{
Serial.print("no signal");
Serial.print("State = 1");
contador = 0;
delay(1000);
}
if((Serial3.available() > 0))
{
a = Serial3.read();
buffer[contador] = a;
Serial.print(buffer[contador]);
///Serial.print(a);
contador++;
contador_errors = 0;
if(a == 's')
{
state = 1;
}
if(a == 'f')
{
contador = 0;
h++;
if(h >= 40)
{
state = 1;
}
}
}
}
while (state == 1)
{
long int n;
n = atol(buffer2);
Serial.println(n);
delay(3000);
contador = 0;
h = 0;
state = 0;
}
}