mardi 3 mai 2022

Varying the time in a Timeout function

#include "mbed.h"

Timeout flipper;
DigitalOut led1(LED1);
DigitalOut led2(LED2);

void flip()
{
    led2 = !led2;
}

int main()
{
    led2 = 1;
    flipper.attach(&flip, 2.0); // setup flipper to call flip       after 2 seconds

    // spin in a main loop. flipper will interrupt it to call flip
    while (1) {
        led1 = !led1;
        ThisThread::sleep_for(200);
    }
}

With this code, is it possible to vary the amount of time the Timeout flipper will be attached for so it could start at 2 seconds, then 3 then 4 etc? And how?

Aucun commentaire:

Enregistrer un commentaire