0

I am trying to program a nonblocking led-blink.

Therefor i programed a little class:

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: };

Then i want to do something like this in loop():

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: }

I call the switchLed() function in loop() with parameter "(&led[0], &ledTimer01)". I think it should work, but my compiler says

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

Where is the problem? Thanks for help :).

steak
  • 2,117
  • 2
  • 13
  • 12

2 Answers2

1

pTimer->checkTimer() has type boolean

So this:

*pTimer->checkTimer()

is invalid as boolean is not of a pointer type.

Same for other functions, why are you using the * operator? This is incorrect:

*pTimer->start();

this is correct:

pTimer->start();

or

(*pTimer).start();  // equivalent to above, prefer the above form
ouah
  • 142,963
  • 15
  • 272
  • 331
  • The "(*pTimer).start()" thing didn't work for me :(. And with the "pTimer->checkTimer()" thing i still get "nonblockingblink:5: error: 'timer' has not been declared". – steak Feb 21 '13 at 21:04
1

You use two types of pointer dereferencing. First you use -> to access the pTimer structure member, and then you use * again on a non-pointer type (the boolean returned by checkTimer). Remove the asterisk and it should work.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621