c - 将 char 和 int 与 concat 混合

标签 c

当我尝试在 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/

相关文章:

c++ - 将区间[0,1]分成(3j-2)个子区间

c - 分配和释放内存,将 100 个数字写入数组,qsort 在 C 中对它们进行排序

c -/usr/lib/dyld 中使用 Valgrind 导致内存泄漏

c - dup2/dup - 为什么我需要复制文件描述符?

c - 如何在 C 编程中泛化 SSCANF 和#DEFINE

c - ARM 链接错误 "Uses VFP register arguments, main.elf does not"仅在 Windows 8 上?

c - 结构不保持 self 类型的原因?

c - void * 函数的输入在函数结束时丢失地址

c - 如何比较 switch-case 中的枚举值?

c - 如何从汇编代码调用 C 函数