7 years, 5 months ago.

I create two timer, and attach it to tow function, but only one can runing

  1. include "mbed.h"

Timeout timeout; Timeout timeout2; DigitalOut led(LED1); DigitalOut led2(LED2);

int on = 1; int cnt = 0; int cnt2 = 0;

void attimeout() { timeout.attach(&attimeout, 0.000004); if(++ cnt == 250000) { cnt = 0; led = !led; } on = 0; }

void attimeout2() { timeout2.attach(&attimeout2, 0.00004); if(++ cnt2 == 25000) { cnt2 = 0; led2 = !led2; } on = 0; }

int main() { timeout.attach(&attimeout, 0.000004); only this one can runing timeout2.attach(&attimeout2,0.00004); while(1); wait(0.2);

}

Be the first to answer this question.