![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
none
Fork of thread-example2 by
Diff: main.cpp
- Revision:
- 1:82ceca58478b
- Parent:
- 0:83abbbeb9a3d
--- a/main.cpp Sat Jan 13 18:26:10 2018 +0000 +++ b/main.cpp Thu Jan 18 17:25:58 2018 +0000 @@ -5,28 +5,38 @@ // Variable for a second thread Thread thread; +volatile int speed; -DigitalOut ledA(LED1); // Red LED -DigitalOut ledB(LED2); // Green LED +DigitalOut ledR(LED1); // Red LED +//DigitalOut ledG(LED2); // Green LED +//DigitalOut ledB(LED3); // Blue LED + +Serial pc(USBTX, USBRX); // tx, rx // This method is run in the second thread -void ledB_thread() { +void led_default() { while (true) { - Thread::wait(250); - ledB = !ledB; + Thread::wait(speed); + ledR = !ledR; } } // This is the main thread int main (void) { - ledA = 1 ; // off - ledB = 1 ; // off - + char c; + speed=250; + ledR=1; + thread.start(callback(led_default)); + while(1) { + pc.printf("\npress f or s>"); + //ledR_thread(speed); + c = pc.getc(); + if (c=='f'){ + speed-=10; + }else if(c=='s'){ + speed+=10; + } // start the second thread - thread.start(callback(ledB_thread)); - - while (true) { - Thread::wait(400); - ledA = !ledA; } } +