i try to read data from serial monitor using the code
#define max_size 40
char data_buffer[max_size];
char question_1[] = "please enter command with value";
void setup(){
Serial.begin(9600);
}//end of setup() function
void loop(){
serial_question(question_1);
serial_check();
serial_output();
}//end of loop() function
void serial_question(char* question){
Serial.println(question);
}//end of serial_question() function
void serial_check(){
while(!Serial.available()){
//wait until user enters the data
}//end of while
while(!received()){
//wait until full message is received
//Serial.println("received");
}//end of while
}//end of serial_check() function
boolean received(){
static byte index = 0;
char input = Serial.read();
if(input == '\r'){
data_buffer[index] = 0;
index =0;
return true;
}
data_buffer[index] = input;
index = index + 1;
return false;
//}//end of received() function
void serial_output(){
Serial.println(data_buffer);
}//end of serial_output() function
But as usual i failed to do so..
and after struggling sometime i got the mistakes in my code..
and right one is
#define max_size 40
char data_buffer[max_size];
char question_1[] = "please enter command with value";
void setup(){
Serial.begin(9600);
}//end of setup() function
void loop(){
serial_question(question_1);
serial_check();
serial_output();
}//end of loop() function
void serial_question(char* question){
Serial.println(question);
}//end of serial_question() function
void serial_check(){
while(!Serial.available()){
//wait until user enters the data
}//end of while
while(!received()){
//wait until full message is received
//Serial.println("received");
}//end of while
}//end of serial_check() function
boolean received(){
if(Serial.available()){
static byte index = 0;
char input = Serial.read();
if(input == '\r'){
data_buffer[index] = 0;
index =0;
return true;
}
data_buffer[index] = input;
index = index + 1;
return false;
}//end of received() function
}
void serial_output(){
Serial.println(data_buffer);
}//end of serial_output() function
and my real question is i got a weird character in serial monitor when i used first code it is like y with two dots above it..
what is that character?