【发布时间】:2018-05-29 08:57:10
【问题描述】:
我有一个 arduino,它通过 6 个单独的输入引脚监听 HIGH 和 LOW 的特定组合。我计划将监听与引脚分开,因为我会根据附加功能定期调用引脚。下面的代码概述了我到目前为止的设置
const int InPins[6] = {3,4,5,6,7,8};
int *PinsReadOut[6] = {0,0,0,0,0,0};
CntlLP = -1;
void setup() {
Serial.begin(115200);
for (int ii = 0, ii > 6, ii++) {
pinMode(InPins[ii],INPUT)
}
}
void loop(){
switch(CntlLP)
case -1:
Serial.println("Waiting for Command");
while (Serial.available()==0){}
CntlLP=Serial.parseInt();
break;
case 1:
ReadPins(PinsReadOut[6]);
CntlLP = -1;
break;
case 2:
if (PinsReadOut[0] == 1) && (PinsReadOut[1] == 1) {
Serial.println("Received 1 & 2");
}
if (PinsReadOut[2] == 1) && (PinsReadOut[3] == 1) {
Serial.println("Received 3 & 4");
}
if (PinsReadOut[4] == 1) && (PinsReadOut[5] == 1) {
Serial.println("Received 5 & 6");
}
CntlLP = -1;
break;
}
void ReadPins(int PinsReadOut[6]) {
for (int ii = 0, ii > 6, ii++) {
PinsReadOut[0] = digitalRead(InPins[ii])
}
}
此代码引发以下错误
warning: ISO C++ forbids comparison between pointer and integer [-fpermissive]
我认为可能将 if 语句更改为 == HIGH 但会导致不同的错误
if (PinsReadOut[0] == HIGH) && (PinsReadOut[1] == HIGH) {
Serial.println("Received 1 & 2");
}
导致此错误
#define HIGH 0x1
编辑:问题更新 我遇到了这个错误。这就是为什么我使用 *.我尝试关注arduino form中的cmets来修复这个错误。
warning: invalid conversion from 'int' to 'int*' [-fpermissive]
【问题讨论】:
-
为什么你有一个指向数组
PinsReadOut的指针?这就是您的警告的来源。 -
@Yksisarvinen 它实际上是指针数组而不是指向数组的指针
-
@bartop 对不起,你当然是对的。
-
我试过了,但结果是另一个错误。经过google,我发现很多人提到为了在函数之间传递一个向量。我应该使用指针。猜我用错了