2017-04-17 108 views
0

我目前正在嘗試製作一個計算器,這是用戶使用紅外遙控器輸入數字的等式的第一部分。Arduino輸出問題

目前我的問題是當我輸入數字作爲字符串輸入到數組中時(所以我可以將它們組合在一起)輸出奇數字符。

這是到目前爲止我的代碼:

#include <boarddefs.h> 
#include <IRremote.h> 
#include <IRremoteInt.h> 
#include <ir_Lego_PF_BitStreamEncoder.h> 


int RECV_PIN = 6; 
IRrecv irrecv(RECV_PIN); 
decode_results results; 

int part1digits = 0; 
String part1[16]; 
void setup() 
{ 
    Serial.begin(9600); 
    irrecv.enableIRIn(); // Start the receiver 
} 

void loop() { 
    if (part1digits <= 15) { 
    while (!irrecv.decode(&results)) { 
     /* DO NOTHING WHEN NO IR SIGNAL IS RECEIVED 
     This WHILE loop will run continuously, doing nothing 
     until there IS a signal received 
     */ 
    } 
    // if IR signals is received, then do this 
    getCode(); 

    part1digits++; 
    } else { 
    for (int i = 0; i <= 15; i++) { 
     Serial.print(part1[part1digits]); 
    } 
    // The while loop below is to 'stop' the program 
while(1){} 

    } 
} 

void getCode() { 
    if (results.value == 16738455) { 
    part1[part1digits] = "0"; 
    Serial.println(part1[part1digits]); 
    } 
    else if (results.value == 16724175) { 
    part1[part1digits] = "1"; 
    Serial.println(part1[part1digits]); 
    } 
    else if (results.value == 16718055) { 
    part1[part1digits] = "2"; 
    Serial.println(part1[part1digits]); 
    } 
    else if (results.value == 16743045) { 
    part1[part1digits] = "3"; 
    Serial.println(part1[part1digits]); 
    } 
    else if (results.value == 16716015) { 
    part1[part1digits] = "4"; 
    Serial.println(part1[part1digits]); 
    } 
    else if (results.value == 16726215) { 
    part1[part1digits] = "5"; 
    Serial.println(part1[part1digits]); 
    } 
    else if (results.value == 16734885) { 
    part1[part1digits] = "6"; 
    Serial.println(part1[part1digits]); 
    } 
    else if (results.value == 16728765) { 
    part1[part1digits] = "7"; 
    Serial.println(part1[part1digits]); 
    } 
    else if (results.value == 16730805) { 
    part1[part1digits] = "8"; 
    Serial.println(part1[part1digits]); 
    } 
    else if (results.value == 16732845) { 
    part1[part1digits] = "9"; 
    Serial.println(part1[part1digits]); 
    } 

    // Serial.println(results.value, HEX); 
    delay(250); // Delay, so you don't send 3 signals back to back 
    // while the button is depressed. 
    irrecv.resume(); // Receive the next value 
} 

輸出後,我在我的所有值都進入我得到的一個小片段是:

ôïÿ9ÝKÏÞóõx;ÿoקÿ^Øè«ÙÝ™ë]^ �ßå¿n'Þ 

回答

0

這是因爲你選擇了錯誤的串行監視器上的波特率。該代碼表示​​9600,因此請確保以該波特率選擇串行監視器。

0

再次檢查您的波特率,嘗試更改9600,38400或57600之間的波特率