This is my code................
int led=13;
int led2=5;
char dataBuff[10];
int count=0;
boolean b=true;
void setup()
{
pinMode(led,OUTPUT);
pinMode(led2,OUTPUT);
Serial.begin(9600);
delay(100);
}
void loop()
{
digitalWrite(led,LOW);
digitalWrite(led2,HIGH);
Serial.write("Waiting for Data");
Serial.println();
delay(1000);
while(b);
digitalWrite(led2,LOW);
digitalWrite(led,HIGH);
delay(1000);
Serial.write("The Received Bytes are:");
Serial.println();
Serial.write("Count Value");
Serial.write(count);
Serial.println();
int i=0;
for(i=0;i<10;i++)
{
Serial.write(dataBuff[i]);
Serial.write("-");
delay(100);
}
while(true);
}
void serialEvent(){
char ch;
while(Serial.available()>0)
{
ch=(char)Serial.read();
if(ch=='*') // '*' this indicates end of transmission
{
b=false;
break;
}
if(ch==' ') // ' ' spaces between bytes of data...
{
break;
}
dataBuff[count]=ch;
++count;
}
}
i am trying to read 8 bytes of data sent serially with 100ms delay in between trasmission from Atmega16 at 9600 There is no problem in Atmega16 i hav tested it using LED set data is comming as i send them ....
But the code is not working the arduino is reading data but not storing it in array of char...? where am i going wrong...and the boolean 'b' value does not get effected..i hav tried declaring count as static but no output and even count value is also not displayed ....and also tried having delay in while loop to break after 10s but still the data buffer is empty....it prints data like '----------'.....Plz help me out here....?