当我尝试在 Arduino IDE 中编译此代码时,出现错误:“请求‘content’中的成员‘concat’,其属于非类类型‘char’”
有人可以帮我解决这个问题吗?提前致谢!
//Schematic: irled on pin 13 with a resistor that simple
#include <IRremote.h>
IRsend irsend;
char content = ' ';
char character;
// Raw codes for buttons of Samsung remote control BN5900706A
unsigned int buttonPower[68] = {4500, 4450, 550, 1700, 550, 1700, 550, 1700, 550, 550, 600, 550, 550, 600, 550, 550, 550, 600, 550, 1700, 550, 1700, 550, 1650, 600, 550, 550, 600, 550, 550, 550, 600, 550, 550, 600, 550, 550, 1700, 550, 600, 550,550, 550, 600, 550, 550, 600, 550, 550, 550, 600, 1650, 600, 550, 550, 1700, 550, 1700, 550, 1700, 550, 1700, 550, 1700, 550, 1650, 600};
unsigned int buttonRecord[68] = {4450, 4450, 600, 1650, 600, 1650, 600, 1650, 600, 550, 550, 550, 600,550, 550, 600, 550, 550, 600, 1650, 600, 1650, 550, 1700, 550, 600, 550, 550, 550, 600, 550, 550, 600, 550, 550, 1700, 550, 550, 600, 550, 550, 1700, 550, 550, 600, 550, 600, 1650, 550, 600, 550, 550, 600, 1650, 600,1650, 550, 600, 550, 1700, 550, 1650, 600, 550, 550, 1700, 550};
unsigned int buttonPlay[68] = {4500, 4450, 550, 1700, 550, 1700, 550, 1700, 550, 550, 600, 550, 550,550, 600, 550, 550, 600, 550, 1650, 600, 1650, 600, 1650, 600, 550, 550, 550, 600, 550, 600, 550, 550, 550, 600, 1650, 600, 1650, 600, 1650, 550,600, 550, 550, 600, 550, 550, 1700, 550, 550, 600, 550, 550, 550, 600,550, 600, 1650, 550, 1700, 550, 1700, 550, 550, 600, 1650, 600};
unsigned int buttonStop[68] = {4500, 4450, 550, 1650, 600, 1650, 600, 1650, 600, 550, 600, 500, 600, 550, 600, 550, 550, 550, 600, 1650, 600, 1650, 600, 1650, 600, 550, 550, 550, 600, 550, 550, 550, 600, 550, 550, 600, 550, 1700, 550, 1650, 600, 550, 600, 550, 550, 550, 600, 1650, 600, 550, 550, 1700, 550, 550, 600,550, 550, 1700, 550, 1700, 550, 1700, 550, 550, 600, 1650, 600};
// End of codes for buttons of Samsung BN5900706A
void setup()
{
Serial.begin(9600);
}
void loop() {
while(Serial.available()) {
character = Serial.read();
content.concat(character);
// content+=character;
}
if (content !=' ') {
if(content=='buttonPower') {delay(100);irsend.sendRaw(buttonPower,68,38);delay(100);Serial.println("buttonPower sent.");};
if(content=='buttonPlay') {delay(100);irsend.sendRaw(buttonProgramDown,68,38);delay(100);Serial.println("buttonPlaysent.");}
else {irsend.sendRaw(buttonRecord,68,38);};
Serial.println(content);
content=' ';
}
delay(1000);
}
最佳答案
以下部分实际上并没有解决问题:
您可以将 Serial.read()
函数返回的 int
转换为 byte
,如下所示:
character = byte(Serial.read());
编辑:此外,您似乎希望在变量 content
中包含多个字符。一个字节
只能包含一个ASCII字符。为了存储多个字符,我将使用 String
类型:
String content = " ";
此外,您尝试在以下比较中定义字节而不是字符串:
content !=' '
content=='buttonPower'
content=='buttonPlay'
它们应该更改为:
content !=" "
content=="buttonPower"
content=="buttonPlay"
关于c - 将 char 和 int 与 concat 混合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31503119/