Read multiple character on the terminal??
i'm writing small code project - communication between xctu , arduino xbee module
here code have far, basically, when type in "1" or "2" in xctu terminal, arduino activate 1 of output light led,
but want change code able read more character on terminal, example, when type in "one" or "two" in xctu terminal, arduino activate output. can please me on coding???
void setup()
{
serial.begin(9600); //initialize serial
pinmode(7, output); //set pin 7 output *yellow led*
pinmode(6, output); //set pin 6 output *red led*
}
void loop()
{
while(serial.available())
{ //is there read?
char getdata = serial.read(); //if yes, read it
if(getdata == '1'){
serial.println(""); // prints carriage return
digitalwrite(7, high);
serial.print("yellow led on ");
serial.println(""); // prints carriage return
delay(2000);
digitalwrite(7, low);
serial.print("yellow led off ");
serial.println(""); // prints carriage return
}else if(getdata == '2'){
serial.println(""); // prints carriage return
digitalwrite(6, high);
serial.print("red led on ");
serial.println(""); // prints carriage return
delay(2000);
digitalwrite(6, low);
serial.print("red led off ");
serial.println(""); // prints carriage return
}
}
}
here code have far, basically, when type in "1" or "2" in xctu terminal, arduino activate 1 of output light led,
but want change code able read more character on terminal, example, when type in "one" or "two" in xctu terminal, arduino activate output. can please me on coding???
void setup()
{
serial.begin(9600); //initialize serial
pinmode(7, output); //set pin 7 output *yellow led*
pinmode(6, output); //set pin 6 output *red led*
}
void loop()
{
while(serial.available())
{ //is there read?
char getdata = serial.read(); //if yes, read it
if(getdata == '1'){
serial.println(""); // prints carriage return
digitalwrite(7, high);
serial.print("yellow led on ");
serial.println(""); // prints carriage return
delay(2000);
digitalwrite(7, low);
serial.print("yellow led off ");
serial.println(""); // prints carriage return
}else if(getdata == '2'){
serial.println(""); // prints carriage return
digitalwrite(6, high);
serial.print("red led on ");
serial.println(""); // prints carriage return
delay(2000);
digitalwrite(6, low);
serial.print("red led off ");
serial.println(""); // prints carriage return
}
}
}
it'd easier use single letters, but, can if want. put code in code brackets,too.
it can read 1 char @ time, have counter , test if 1st,2nd,3rd value t,w,o? or maybe add each input string , test string?
it can read 1 char @ time, have counter , test if 1st,2nd,3rd value t,w,o? or maybe add each input string , test string?
Arduino Forum > Using Arduino > Programming Questions > Read multiple character on the terminal??
arduino
Comments
Post a Comment