Passing an object to vTaskCreatePinToCore

Hello, I am trying to pass an object (specifically an Addafruit_NeoPixel instance)
to a routine using vTaskCreatePinToCore but I cannot seem to figure out how to make it work.

The Task Creation functions take a void* parameter that is passed to the task. Pass the ADDRESS of the object to the task through that, and have it access the object through that pointer. (Use the & operator on the object)

Unless the object is no bigger than a void*, you can’t directly pass the object itself, just its address. If the object is just a “Handle” which is just a pointer in disguise, then you might be able to coerce the handle into the void* pointer and back.

Thanks. I think that worked. Now I cant figure out how to use the object in the task it called. Here is an excerpt of what I have:

Adafruit_NeoPixel psiFront(PSI_PIXEL_COUNT, PSI_FRONT_PIN, NEO_GRB + NEO_KHZ800);			// Create front PSI object and assign the name psiFront

 xTaskCreatePinnedToCore(lampTest,"lampTest",1000,(void*)std::addressof(psiFront),1,NULL,1);

void lampTest(void* pvParameters)
{

	Adafruit_NeoPixel Display = * pvParameters; // <---- This doesn't work. How do I re-associate the Display to the address of pvParameters?
}




Just cast it to the underlying type e.g. like this:

Adafruit_NeoPixel& Display = *((Adafruit_NeoPixel*)pvParameters);

because that’s the contract regarding pvParameter.
BUT you have to ensure that the object you want to transfer by reference/pointer is persistent resp. is kept alive ! A local/stack allocated object might be ok, but only if the original object never goes out of scope and is created in an already a running task which is never deleted.

That isn’t working either. the IDE is giving me the squigglies under the Display* and pvParameters.

The Display* is saying expecting a “)” and the pvParameters says no suitable constructor exists to convert from void to Adafruit_NeoPixel.

Sorry, I cam from the VB-NET world.

Ahh sorry - fixed the copy’n paste typo (removed wrong Display) in the post.