I have the Main file and 2 classes.
RGBLEDClass - Controls RGB Led
TimedAction - Purely for photothreading
Goal:
Have a blinking Red RGB LED while hardware is in setup process and switch to Green when ready
Issue:
Cannot use delay() to blink LED as components need to run as part of my setup
Therefore, I use the TimedAction library which allows you to set an interval and the in the loop it will check if that interval has passed and executes
When passing a normal function:
#include "RGBLEDClass.h"
#include "TimedAction.h"
RGBLEDClass *RGBLEDClassPtr;
void setup() {
Serial.begin(9600);
RGBLEDClassPtr = new RGBLEDClass(11, 9, 10);
RGBLEDClassPtr->setColourRGB(255, 0, 0);
RGBLEDClassPtr->changeLEDState(true);
//Create your own timed action but me tired
}
// DOES NOT WORK - error: no matching function for call to 'TimedAction::TimedAction(int, <unresolved overloaded function type>)'
// TimedAction LEDBlink = TimedAction(1000, RGBLEDClassPtr->changeLEDState);
// WORKS
TimedAction LEDBlink = TimedAction(1000, test);
void loop() {
}
void test() {
Serial.println("Im working");
}
void cleanUp() {
delete RGBLEDClassPtr;
RGBLEDClassPtr = NULL;
}
it works perfectly! However when passing a function from the RGBLEDClass (changeLEDState() to be exact) into the TimedAction function I get the following error:
error: no matching function for call to 'TimedAction::TimedAction(int, )'
The TimedAction constructor:
TimedAction::TimedAction(unsigned long intervl,void (*function)()){
active = true;
previous = 0;
interval = intervl;
execute = function;
}
I understand that this is an issue with "void (*function)()" parameter and because the parameter being passed will actually be "this->changeLEDState()" making it 2 parameters but I do not know what to change the parameter value to let the constructor take function pointers.
Please help, I'm struggling!
I have attached all the files being used for some of you C++ smarties to tinker with!
RGBLEDClass.cpp (2.68 KB)
RGBLEDClass.h (503 Bytes)
RGBLEDPWMTimed.ino (740 Bytes)
TimedAction.cpp (793 Bytes)
TimedAction.h (2.13 KB)