我試圖編程一個非阻塞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
問題出在哪裏? 感謝您的幫助:)。
你在哪裏有代碼(我的意思是文件)?你如何編譯它? – m0skit0 2013-02-21 20:56:22
有一件事是,'pTimer->'前面的指針,當使用' - >'符號時,不要在它之前使用'*') – 2013-02-21 20:57:05
'* pTimer-> checkTimer()'應該是'pTimer-> checkTimer()'。 – 2013-02-21 20:57:18