Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years, 4 months ago.
[RTOS] - Conditional flow between threads
Good morning,
I'm starting to work with the mbed RTOS but I'm not being very fortunate. I'm currently trying to implement the program below: if a user presses a key different from "1", then a led will be lit; if the pressed key is "1", then the led has to be off. I'm not able to enter and exit the tasks as I was hopping. Can anyone help?
Conditional RTOS
#include "mbed.h"
#include "rtos.h"
Serial pc(USBTX,USBRX);
DigitalOut led1(LED1);
Semaphore hold(1);
char data=' ';
int i=10;
void ledon(void const *args)
{
pc.printf("LED on.\n");
led1=1;
}
void ledoff(void const *args)
{
hold.wait();
for (i=10; i<1; i--) {
pc.printf("LED off in: %i\n", i);
Thread::wait(1000);
}
led1=0;
Thread::wait(500);
hold.release();
}
int main()
{
Thread ledup(ledon);
Thread leddown(ledoff);
while(true) {
dados=pc.getc();
pc.printf("Pressed key was %c\n", data);
if (dados == '1') {
Thread leddown(ledoff);
}
if (dados != '1') {
Thread ledup(ledon);
}
}
}