Hi guys;
I am trying to send data from an Ardiuno ( reading a analog pin ) to a PC and from the PC to the Arduino ( LCD display ).
So far, I did send, received and display the data, but how can I wait for the incomming data without keep sending serial out.
My code just do that at the moment. I send the data like : < 345>< 678>< 234>.... can not hold yet... In the Serial Sending Box : I type : 2.365> and it display on the LCD --> V : 2.365 Volt I leat I got that working, but I want to hold or wait for the incomming data. I did that ---> the comment section but it do : < 567> I type : 2.356 I received : 2 and it send < 789>< 675>
Here my code. Any tips and help will be nice. Programming is not my strong point here. About the values being send, I simply read an open analog pin at the moment.
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,10,9,8,7);
const byte anapin = 2;
unsigned int my_value;
unsigned char incom[8];
int j;
boolean state;
void setup()
{
analogReference(DEFAULT);
Serial.begin(9600);
lcd.begin(16,2);
lcd.clear();
lcd.print("V : ");
lcd.setCursor(11,0);
lcd.print(" Volt");
for (int i=0;i<8;i++)
{
incom[i]=0x20;
}
}
void loop()
{
my_value = analogRead(anapin);
Serial.print("<");
if ( my_value < 999 )
{
Serial.print(" ");
}
Serial.print(my_value, DEC);
Serial.print(">");
delay(1000);
/*
state=1;
if (Serial.available() >0) state=0;
else state=1;
while (state==1)
{
if (Serial.available() >0) state=0;
else state=1;
}
*/
j=0;
while ( Serial.available() > 0 )
{
incom[j] = Serial.read();
if (incom[j]=='>' ) break;
j++;
if (j==8) break;
}
for (int i=0;i<8;i++)
{
if (incom[i]=='>') break;
lcd.setCursor((4+i),0);
lcd.write(incom[i]);
}
delay(1000);
}