A very simple example of an RTOS executing on an LPC1768 Platform
Fork of app-board-RTOS-Threads by
main.cpp
- Committer:
- TheFella
- Date:
- 2016-08-08
- Revision:
- 5:d6da74ac1cc3
- Parent:
- 4:79863d2ea5a0
- Child:
- 6:7f833d7ef195
File content as of revision 5:d6da74ac1cc3:
// example to test the mbed Lab Board lcd lib with the mbed rtos // Pot1 changes the contrast // Pot2 changes the speed of the sin wave #include "mbed.h" #include "rtos.h" #include "Small_6.h" #include "Small_7.h" #include "Arial_9.h" #include "stdio.h" #include "C12832_lcd.h" #define LEDON 1 #define LEDOFF 0 Serial pc(USBTX, USBRX); AnalogIn Pot1(p19); AnalogIn Pot2(p20); DigitalOut led1(LED1); DigitalOut led2(LED2); // mutex to make the serial thread safe Mutex pc_mutex; // Thread 1 // print counter into first line and wait for 1 s void thread1(void const *args) { int i; while(true) { // thread loop pc_mutex.lock(); pc.printf("Thread1 count: %d\n\r",i); pc_mutex.unlock(); i++; Thread::wait(1000); } } // Thread 2 // print counter into third line and wait for 0,5s void thread2(void const *args) { int k; while(true) { // thread loop pc_mutex.lock(); pc.printf("Thread 2 count : %d\n\r",k); pc_mutex.unlock(); k++; Thread::wait(500); // wait 0.5s } } // Thread 4 // the value of pot 1 changes the DC of LED1 void thread4(void const *args) { while(true) { // thread loop pc_mutex.lock(); if( Pot1.read_u16() > 0xEFFF) { led1 = LEDON; } else { led1 = LEDOFF; } pc_mutex.unlock(); } Thread::wait(500); // value of pot1 / 100 } // Thread 5 // the value of pot 2 changes the DC of LED2 void thread5(void const *args) { while(true) { // thread loop pc_mutex.lock(); if( Pot2.read_u16() > 0xEFFF) { led2 = LEDON; } else { led2 = LEDOFF; } pc_mutex.unlock(); } Thread::wait(500); // value of pot1 / 100 } int main() { Thread t1(thread1); //start thread1 Thread t2(thread2); //start thread2 Thread t4(thread4); //start thread4 Thread t5(thread5); //start thread5 while(true) { // main is the next thread pc_mutex.lock(); pc_mutex.unlock(); Thread::wait(500); // wait 0.5s } }