【问题标题】:Arduino output problemsArduino输出问题
【发布时间】:2017-04-18 21:45:35
【问题描述】:

我目前正在尝试制作一个计算器,这是等式的第一部分,用户将使用红外遥控器输入一个数字。

目前我的问题是,当我将输入到数组中的数字作为字符串输出时(这样我以后可以将它们组合起来),它会输出奇数字符。

这是我目前的代码:

#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'Þ

【问题讨论】:

    标签: arduino


    【解决方案1】:

    发生这种情况是因为您在串行监视器上选择了错误的波特率。代码显示为 9600,因此请确保以该波特率选择串行监视器。

    【讨论】:

      【解决方案2】:

      再次检查您的波特率,尝试在 9600、38400 或 57600 之间更改波特率

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-12-22
        • 1970-01-01
        • 2012-06-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多