Timeout callback does not seem to fire

I’m trying to toggle an LED in a Timeout callback.

DigitalOut led(LED1);

class PPMOut {
public:
        PPMOut(DigitalOut led);
protected:
        Timeout timeout;
        DigitalOut _led;

        void timeout_expired();
};

PPMOut::PPMOut(DigitalOut led) : _led(led) {
        timeout.attach_us(callback(this, &PPMOut::timeout_expired), 100000);
}

void PPMOut::timeout_expired() {
        _led = !_led;
}

This constructs fine. Using a Thread will work, but this will not. What am I doing wrong?

DigitalOut led(LED1);

int main() {
    PPMOut pout(led);
    while (true) ThisThread::sleep_for(100);
}

Hello Sid,

I think it works, but it toggles the LED1 only once (it turns the LED1 on). To toggle the LED1 periodically the callback should be reattached in the callback:

void PPMOut::timeout_expired() {
    _led = !_led;
    timeout.attach_us(callback(this, &PPMOut::timeout_expired), 100000);
}

NOTE:
The Ticker does the same automatically. Actually, it is a Timeout with built-in reattach.

Thanks Zoltan. That was the issue, I missed ticker and assumed timeout subsumed it.