none

Fork of thread-example2 by William Marsh

main.cpp

Committer:
edwinkad
Date:
2018-01-18
Revision:
1:82ceca58478b
Parent:
0:83abbbeb9a3d

File content as of revision 1:82ceca58478b:

// Simple Example fo use of Threads on mbed OS 5
//   Only need to include mbed.h

#include "mbed.h"

// Variable for a second thread
Thread thread;
volatile int speed;

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 led_default() {
    while (true) {
        Thread::wait(speed);
        ledR = !ledR;
    }
}

// This is the main thread
int main (void) {
    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
    }
}