Hi! I’m very very rusty and I’m having huge problems solving this issue.
I have a class (LEDController) that is supposed to show some numbers on a 7 digit LDC.
In one scenario I want to “animate” the segments (like a wait spinner).
I want to start the “spinner” with the funtction “waitspinner” so it might look like this:
display.waitspinner(i2c_address, bool *isSpinning);
In the waitspinner I want to start a new thread so I can do a loop and show segments.
Here is my code so far, but I cannot understand how to create a new thread here
void LEDController::doSpin(int display, bool cancellationAsked) {
char buffer[11];
char bit = 0b00000001;
while (!cancellationAsked) {
for (int i = 0; i < 6; i++) {
buffer[0] = 0x00;
buffer[1] = bit;
buffer[2] = 0xFF;
buffer[3] = bit;
buffer[4] = 0xFF;
buffer[5] = 0x00;
buffer[6] = 0xFF;
buffer[7] = bit;
buffer[8] = 0xFF;
buffer[9] = bit;
buffer[10] = 0xFF;
i2c->write(display, buffer, 11);
bit = bit << 1;
ThisThread::sleep_for(200ms);
}
}
}
void LEDController::waitSpin(int display, bool cancellationAsked) {
Thread thread;
thread.start(callback(doSpin, display, cancellationAsked));
thread.join();
}