Not Complete

Dependencies:   mbed

Fork of Nucleo_rtos by ST

main.cpp

Committer:
bcostm
Date:
2015-04-16
Revision:
73:d3b295249699
Child:
77:cd59ac40b3be

File content as of revision 73:d3b295249699:

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

DigitalOut led(LED1);

InterruptIn button(USER_BUTTON);

uint32_t button_pressed;
Thread *thread2;

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

void led_thread(void const *argument)
{
    while (true) {
        led = !led;
        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);

    printf("mbed RTOS example\n");
    
    button_pressed = 0;
    button.fall(&button_press);
    
    while (true) {
        Thread::wait(6000);
        printf("During the last 6 seconds, the Button was pressed %d times\n", button_pressed);
        fflush(stdout);
        button_pressed = 0;
    }
}