2016-06-17 34 views
0

所以我想用串行通信到arduino。我希望它打印出「射擊電機」當我輸入1.我這裏有程序:Arduino Micro Serial.print字符串不返回字符串

void setup() { 
    Serial.begin(9600); //Connect to the serial monitor console 
} 

void loop() { 
    while (Serial.available() == 0); //Wait until Serial is available 

    //Read val 
    int val = Serial.read() - '0'; //Val that represents input 
    Serial.print(val); 

    delay(1000); 
    if (val == 1) { 
     Serial.print('Firing the motor.'); 
    } else { 
     Serial.print('Please press 1 to fire the motor.'); 
    } 

    delay(4000); 
} 

的問題是,而不是返回「燒電機。」或「請按1啓動電機。」所有的控制檯簡單地返回0。我也試圖消除 - 「0」

我也試着說:

if (val == 1) { 
    Serial.print("Firing the motor."); 
} else { 
    Serial.print("Please press 1 to fire the motor."); 
} 

和增加的「」不是「」

感謝您的任何幫助

回答

0

您是否將顯示器設置爲相同的波特率? (9600) 我的意思是 image

+0

是的,它被設置爲9600 –