Softtimer 2

I am trying to use softtimer. But when complie, error says

Arduino:1.6.6 (Windows 7), Board:“Arduino/Genuino Uno”

softtimer2:6: error: ‘turnOn’ was not declared in this scope

Task taskOn(2000, turnOn);

^

softtimer2:8: error: ‘turnOff’ was not declared in this scope

Task taskOff(1111, turnOff);

^

exit status 1
‘turnOn’ was not declared in this scope

How to declare ‘turnON’? Please help me.

my code is

#include <SoftTimer.h>

// – taskOn will be launched on every 2 seconds.
Task taskOn(2000, turnOn);
// – taskOff will be launched on every 1111 milliseconds.
Task taskOff(1111, turnOff);

void setup() {
// – Mark pin 13 as an output pin.
pinMode(13, OUTPUT);

// – Register the tasks to the timer manager. Both tasks will start immediately.
SoftTimer.add(&taskOn);
SoftTimer.add(&taskOff);
}

/**

  • Turn ON Arduino’s LED on pin 13.
    /
    void turnOn(Task
    me) {
    digitalWrite(13, HIGH);
    }

/**

  • Turn OFF Arduino’s LED on pin 13.
    /
    void turnOff(Task
    me) {
    digitalWrite(13, LOW);
    }

The problem is caused by this bug: Auto prototype generation with function as argument to class instantiation · Issue #50 · arduino/arduino-builder · GitHub
The new arduino-builder preprocessor added in Arduino IDE 1.6.6 fails to properly place the automatically generated function prototypes for turnOn() and turnOff() in the correct location. So you need to manually add function prototypes for them:

#include <SoftTimer.h>

//callback function prototypes
void turnOn(Task* me);
void turnOff(Task* me);

// -- taskOn will be launched on every 2 seconds.
Task taskOn(2000, turnOn);
// -- taskOff will be launched on every 1111 milliseconds.
Task taskOff(1111, turnOff);

void setup() {
  // -- Mark pin 13 as an output pin.
  pinMode(13, OUTPUT);

  // -- Register the tasks to the timer manager. Both tasks will start immediately.
  SoftTimer.add(&taskOn);
  SoftTimer.add(&taskOff);
}

/**
   Turn ON Arduino's LED on pin 13.
*/
void turnOn(Task* me) {
  digitalWrite(13, HIGH);
}

/**
   Turn OFF Arduino's LED on pin 13.
*/
void turnOff(Task* me) {
  digitalWrite(13, LOW);
}

In the future please use the code tags button </> when you post code and console output on the forum.

I was going to submit a pull request to fix this issue in the SoftTimer examples but the library author is already aware of the problem and is not willing to make the change. https://github.com/prampec/arduino-softtimer/issues/6 It's unfortunate that they would take that attitude about such a simple change to solve a problem that will cause the examples to not compile for most users.

Thanks alot!

I added the code, void turnOn(Task* me); void turnOff(Task* me); that you sugested but I got error,

Arduino:1.6.7 (Windows 8.1), Board:“Arduino/Genuino Uno”

In file included from C:\Users\jk\Documents\Arduino\libraries\SoftTimer\src\Debouncer.cpp:28:0:

C:\Users\jk\Documents\Arduino\libraries\SoftTimer\src\Debouncer.h:32:25: fatal error: PciListener.h: No such file or directory

#include <PciListener.h>

^

compilation terminated.

exit status 1

How can I solve?

That’s from another library that you need to install to use SoftTimer: Sketch > Include Library > Manage Libraries… > Filter your search… > PciManager > Install

I installed PciManager but it says the same error

In file included from C:\Users\jk\Documents\Arduino\libraries\SoftTimer\src\Debouncer.cpp:28:0:

C:\Users\jk\Documents\Arduino\libraries\SoftTimer\src\Debouncer.h:32:39: fatal error: ../PciManager/PciListener.h: No such file or directory

include "../PciManager/PciListener.h"

^

compilation terminated.

exit status 1

It was fixed. THANKS ALOT1.

kimsan:

include "../PciManager/PciListener.h"

You must be using an older version of SoftTimer. Try updating by Sketch > Include Library > Manage Libraries... > Filter your search... > SoftTimer > Install and see if that fixes the error.