Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Task631-mbedos54 by
main.cpp
- Committer:
- noutram
- Date:
- 2016-03-14
- Revision:
- 6:2e463846b575
- Parent:
- 5:31707531f715
- Child:
- 7:cd015e83995a
File content as of revision 6:2e463846b575:
#include "mbed.h"
#include "rtos.h"
#include "string.h"
#include <stdio.h>
#include <ctype.h>
#define DELAY 200
//Digital outputs
DigitalOut onBoardLED(LED1);
DigitalOut redLED(D7);
DigitalOut yellowLED(D6);
DigitalOut greenLED(D5);
//Serial Interface
Serial pc(USBTX, USBRX);
//Digital inputs
DigitalIn onBoardSwitch(USER_BUTTON);
DigitalIn SW1(D4);
DigitalIn SW2(D3);
//Thread ID for the Main function (CMSIS API)
osThreadId tidMain;
void thread1( const void* arg )
{
pc.printf("Entering thread 1\n");
while (true) {
yellowLED = 1;
Thread::wait(DELAY);
yellowLED = 0;
Thread::wait(DELAY);
}
}
//This thread has higher priority
void thread2( const void* arg )
{
pc.printf("Entering thread 2\n");
while (true) {
redLED = 1;
if (SW1 == 1) {
//wait_ms(osWaitForever);
Thread::wait(osWaitForever);
} else {
Thread::wait(DELAY);
}
redLED = 0;
Thread::wait(DELAY);
}
}
//Main thread
int main() {
redLED = 0;
yellowLED = 0;
greenLED = 0;
//Main thread ID
tidMain = Thread::gettid();
//Threads
Thread t1(thread1, NULL, osPriorityNormal);
//Thread t2(thread2, NULL, osPriorityNormal);
Thread t2(thread2, NULL, osPriorityAboveNormal);
pc.printf("Main Thread\n");
while (true) {
Thread::wait(osWaitForever);
}
}