2013-02-21 55 views
-1

我试图编程一个非阻塞led指示灯。Arduino编译器抛出“一元*的无效类型参数”

为此我程序性有点类:

03: class timer { 
04: private: 
05: int startMillis; 
06: int delayMillis; 
07: public: 
08: timer (int pDelay) { 
09: reset (pDelay); 
10: } 
11: void start() { 
12: startMillis = millis(); 
13: } 
14: void reset (int pDelay) { 
15:  delayMillis = pDelay;  
16: } 
17: boolean checkTimer() { 
18:  if ((millis() - startMillis) >= delayMillis) { 
19:  return true; 
20:  } else { 
21:  return false; 
22:  } 
23: } 
24: }; 

然后我想要做的循环是这样的():

42: void switchLed (int *pPin, timer *pTimer) { 
43: if ((*pTimer->checkTimer()) == true) { 
44:  if (bitRead(PORTD, *pPin) == HIGH) { 
45:  digitalWrite(*pPin, LOW); 
46:  } else {  
47:  digitalWrite(*pPin, HIGH); 
48:  } 
49:  *pTimer->start(); 
50: } 
51: } 

我称之为循环的switchLed()()函数与参数“(& led [0],& ledTimer01)”。 我认为它应该工作,但是我的编译器说

nonblockingblink:5: error: 'timer' has not been declared 
nonblockingblink.ino: In function 'void switchLed(int*, timer*)': 
nonblockingblink:43: error: invalid type argument of 'unary *' 
nonblockingblink:49: error: void value not ignored as it ought to be 

问题出在哪里? 感谢您的帮助:)。

+1

你在哪里有代码(我的意思是文件)?你如何编译它? – m0skit0 2013-02-21 20:56:22

+0

有一件事是,'pTimer->'前面的指针,当使用' - >'符号时,不要在它之前使用'*') – 2013-02-21 20:57:05

+1

'* pTimer-> checkTimer()'应该是'pTimer-> checkTimer()'。 – 2013-02-21 20:57:18

回答

1

pTimer->checkTimer()具有类型boolean

所以这个:

*pTimer->checkTimer() 

是无效的,因为boolean为指针类型的不是。

与其他功能相同,为什么使用*运算符? 这是不正确的:

*pTimer->start(); 

这是正确的:

pTimer->start(); 

(*pTimer).start(); // equivalent to above, prefer the above form 
+0

“(* pTimer).start()”的东西没有为我工作:(。与“pTimer-> checkTimer()”的事情,我仍然得到“nonblockingblink:5:错误:'计时器'尚未宣布”。 – blackWorX 2013-02-21 21:04:47

1

您可以使用两种类型的指针废弃的。首先使用->来访问pTimer结构成员,然后在非指针类型(由checkTimer返回的boolean)上再次使用*。删除星号,它应该工作。

相关问题