【问题标题】:error: expected primary-expression before '{' token错误:“{”标记之前的预期主表达式
【发布时间】:2013-10-15 19:28:02
【问题描述】:

有人可以帮我解决代码问题吗?我得到了通用编译错误: 错误:“{”标记之前的预期主表达式

加上这部分代码代码:

for (int i=0; i<2; i++) { 

   PotValue[i] = analogRead(PotPin[i]);   //This is the error line

   MappedPotValue[i]=(PotValue[i]+1)/103;

 //SomeCode Here
}

所以。我的目标是在 PotValue 数组中写入 Arduino Board 中所有 Pot 的所有值

PotValue 和 MappedPotValue 是长度为 2 的 int 数组

PotPin 已被声明为:

#define PotPin {A0, A1} // These are two analog pins on arduino board

for 循环在定时器中断中

谢谢帮助

【问题讨论】:

  • analogRead 采取什么论据?

标签: c++ arrays for-loop arduino


【解决方案1】:
analogRead(PotPin[i]);

被解析为:

analogRead({A0, A1}[i]);

这是一个语法错误。 C 或 C++ 中没有数组字面量。

【讨论】:

    【解决方案2】:

    您应该避免使用预处理器。用这个代替#define:

    static const int PotPin[] = {A0, A1};
    

    (根据需要调整类型int)。

    【讨论】:

      猜你喜欢
      • 2013-01-13
      • 2017-09-24
      • 2012-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多