![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
A mbed RTOS based multimeter application that sends results to a phone over the Bluetooth module.
Dependencies: LCD_DISCO_F429ZI mbed mbed-rtos BSP_DISCO_F429ZI
Diff: main.cpp
- Revision:
- 13:d21f6477ba19
- Parent:
- 12:441ee5b1cf71
- Child:
- 14:526e0b503646
--- a/main.cpp Sun Jan 17 19:51:15 2021 +0000 +++ b/main.cpp Sun Jan 17 20:23:19 2021 +0000 @@ -6,17 +6,19 @@ //float message_t //MemoryPool<message_t, 10> mpool; //Queue<message_t, > queue; +semaphore one_slot(1); -Serial bluetooth(PA_9, PA_10);//Tx, Rx -AnalogIn ain(PA_0); //potentiometer +Serial bluetooth(PA_9, PA_10); //Blueutooth Tx, Rx +AnalogIn ain(PA_2); //Potentiometer Input DigitalOut led1(LED1); DigitalOut led2(LED2); -//DigitalIn btn1(PA_0); //Button on your Nucleo Board -LCD_DISCO_F429ZI lcd; -Thread thread1; //thread(osPriority osPriorityNormal) +LCD_DISCO_F429ZI lcd; //LCD Library +Thread thread1; //threads Thread thread2; +Thread thread3; +Thread thread4; void thread1_function() { lcd.Clear(LCD_COLOR_WHITE); @@ -42,6 +44,7 @@ Thread::wait(1000); } } + void thread2_function() { lcd.DisplayStringAt(0, LINE(2), (uint8_t *)"TASK2 RUNNING", CENTER_MODE); printf("Task2 Running\n\r"); @@ -51,10 +54,18 @@ //led2 = !led2; bluetooth.printf("Hello World !\r\n"); Thread::wait(1000); - //bluetooth.printf("This program runs since %f seconds.\r\n", i++); + //bluetooth.printf("This program runs since %f seconds.\r\n", i++); +} +} - -} +void semaphore_test(void const *name) +{ + while (true) { + one_slot.acquire(); + printf("%s\n\r", (const char *)name); + ThisThread::sleep_for(1000); + one_slot.release(); + } } int main() { @@ -62,12 +73,18 @@ thread1.set_priority(osPriorityHigh); thread2.set_priority(osPriorityNormal); + thread1.start(thread1_function); // Starting the processes thread2.start(thread2_function); + thread3.start(test_thread, (void *)"Thread 3"); + thread4.start(test_thread, (void *)"Thread 4"); + thread1.join(); thread2.join(); + thread3.join(); + thread4.join(); //wait for threads to complete printf("The end of main.\n\r");