我目前正在尝试制作计算器,这是用户使用IR遥控器输入数字的等式的第一部分。
目前我的问题是当我输出我作为字符串输入到数组中的数字时(所以我可以稍后将它们组合起来)它输出奇数字符。
到目前为止,这是我的代码:
#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 :(得分:0)
这是因为您在串行监视器上选择了错误的波特率。代码为9600,因此请确保以该波特率选择串行监视器。
答案 1 :(得分:0)
再次检查您的波特率,尝试在9600,38400或57600之间更改波特率