該程序是爲了讀取輸入,並將其寫入Arduino的串行監視器中。它只在串行監視器中寫入一個字符的問題。Arduino只讀取一個字符。
void setup()
{
Serial.begin(9600); //Set the serial monitor.
lcd.begin(16, 2); //Set the LCD
}
// Alignment variables
boolean left = true; //Set boolean left to true to begin to display text in middle of screen.
boolean right = false; //Other possible align booleans set to false
boolean select = false;
//Text show/hide variables
boolean show1 = true; //Both values set to true to display on start up.
boolean show2 = true;
//Serial input
char serialinput [4] = {0}; //For 3 value input, and null character to end.
char line1;
void loop()
{
if (Serial.available() > 0) { //If the serial monitor is open it will read a value.
line1 = Serial.read();
Serial.print(line1);
memmove (serialinput, &serialinput[1], 3); //copy the value to memory
serialinput [2] = Serial.read(); //value is read.
//if statements for each possible input.
}
既然'line1'是一個'char',你怎麼期望它處理多個字符呢? –