As you can see, I am checking if the Task is running when the button is pressed. If it is not running, it will run the Task. However, liftMacro is not initialized until after the condition, how do I declare the Task /solve this issue. The error says: “use of undeclared identifier ‘liftMacro’”
I want the task to only run when the button is pressed. If I move it to where it is longer living, wouldn’t it keep running?
There isn’t a deconstructor for the task, so the underlying allocated FreeRTOS task’s lifetime is the same in both cases. I also recommend reading a few C++ tutorials on scope and such. You’re attempting to create a new task every time you go around your loop, which will cause a lot of problems.
Tasks are supposed to be long living for a variety of reasons, and that isn’t what you’re doing. While you likely can get it to work, I’d recommend communicating cross task by sending something like a task notification when you want to start/stop the macro. This will also make lifetime tracking easier as you only start up your macro’s task once.