Thread UART

Dependencies:   fsl_phy_mcr20a fsl_smac mbed-rtos mbed

Fork of mcr20_wireless_uart by samuel belete

main.cpp

Committer:
cotigac
Date:
2015-04-03
Revision:
18:b02fc0e53df8
Parent:
17:52cfd7db8da3
Child:
19:71b793021c78

File content as of revision 18:b02fc0e53df8:

#include "mbed.h"
#include "rtos.h"

DigitalOut led1(LED1);
InterruptIn sw2(SW2);
uint32_t button_pressed;
Thread *thread2;

void sw2_press(void)
{
    thread2->signal_set(0x1);
}

void led_thread(void const *argument)
{
    while (true) {
        led1 = !led1;
        Thread::wait(1000);
    }
}

void button_thread(void const *argument)
{
    while (true) {
        Thread::signal_wait(0x1);
        button_pressed++;
    }
}

int main()
{
    Thread thread(led_thread);
    thread2 = new Thread(button_thread);

    button_pressed = 0;
    sw2.fall(&sw2_press);
    while (true) {
        Thread::wait(5000);
        printf("SW2 was pressed (last 5 seconds): %d \r\n", button_pressed);
        fflush(stdout);
        button_pressed = 0;
    }
}