I have successfully implemented some code which uses a linked-list. Everything is working, except assigning a value to a float within the embeded class. When I run the code below, I get the expected behavior, a flashing LED for 10 secs then LED turns continuously ON, and I also get the debug messages I expect. However, when I comment the marked line to assign a value to the float, it still compiles, but the LED does not flash as expected and I get complete rubbish from debug. I am using codebender on Chrome, and I have tried Firefox (both given same results).
Main Sketch https://codebender.cc/sketch:175995
Example of library working https://codebender.cc/sketch:176008
Can anyone help?
typedef void(*GF)(void);
#include "LinkedList.h"
class CsC {
public:
float PerS;
GF FunctionToCall;
};
LinkedList<CsC*> TaskList = LinkedList<CsC*>();
void LEDON()
{
digitalWrite(13,HIGH);
}
void after(float interval, String intervalDescription, GF func);
void after(float interval, String intervalDescription, GF func)
{
float multi = 1;
if(intervalDescription == "mins") multi *= 60;
float delayMS = multi * interval;
CsC *c;
//Error if either of these lines uncommented
//c->PerS=10000;
//c->PerS=delayMS;
c->FunctionToCall=func;
TaskList.add(c);
Serial.print(".");
}
void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);
Serial.println("Start write task list");
after(35,"secs",LEDON);
Serial.println("Done");
Serial.println("Start prog");
}
void loop()
{
Serial.print("List=");
Serial.print(TaskList.size());
while(TaskList.size()>0){
CsC *c=TaskList.shift();
long timeout=millis()+10000;
//long timeout=millis()+((long)(c->PerS*1000.0));
while(millis()<timeout){
//To indicate it is running, and to save time, I have used a delay here
digitalWrite(13,HIGH);
delay(250);
digitalWrite(13,LOW);
delay(250);
}
c->FunctionToCall();
}
Serial.print(".");
Serial.println("complete");
while(1){}
}
c
?new
operator. And you deallocate it with thedelete
operator.