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

Revision:
14:526e0b503646
Parent:
13:d21f6477ba19
Child:
15:9c5fb6600570
--- a/main.cpp	Sun Jan 17 20:23:19 2021 +0000
+++ b/main.cpp	Sun Jan 17 21:38:16 2021 +0000
@@ -6,10 +6,11 @@
 //float message_t
 //MemoryPool<message_t, 10> mpool;
 //Queue<message_t, > queue;
-semaphore one_slot(1);
+Semaphore one_slot(1);
+//InterruptIn button(PA_0);
 
 Serial bluetooth(PA_9, PA_10); //Blueutooth Tx, Rx
-AnalogIn ain(PA_2);           //Potentiometer Input 
+AnalogIn ain(PA_0);           //Potentiometer Input 
 
 DigitalOut led1(LED1);
 DigitalOut led2(LED2);
@@ -20,20 +21,22 @@
 Thread thread3;
 Thread thread4;
  
-void thread1_function() {
+void voltage_function(void const *name) {    
     lcd.Clear(LCD_COLOR_WHITE);
     lcd.DisplayStringAt(0, LINE(1), (uint8_t *)"TASK1 RUNNING", CENTER_MODE);   
     printf("Task1 Running\n\r");               
-    //DigitalOut led1(LED1);
-    //led1 = !led1;
+    led1 = !led1;
     
     float samples[10];
-    float volt_value[10];
+    
 while(1) {
+    one_slot.wait();
+    printf("%s acquires semaphore\n\r", (const char *)name);
+    Thread::wait(1000);
+
     for(int i=0; i<10; i++) {
         //ain.set_reference_voltage(3.0);
         samples[i] = ain.read()*3; 
-        //volt_value[i] = (((float)samples[i])/255.0)*3.0;
         wait(0.001f);
     }
     
@@ -41,45 +44,58 @@
     for(int i=0; i<10; i++) {
         bluetooth.printf("%d = , %f\n", i, samples[i]);
     }
+    printf("Displayed by %s\n\r", (const char *)name);
+    Thread::wait(1000);
+    one_slot.release();
+    printf("%s releases semaphore\n\r", (const char *)name);
     Thread::wait(1000);
 }
 }
 
-void thread2_function() {
+/*void thread2_function() {
     lcd.DisplayStringAt(0, LINE(2), (uint8_t *)"TASK2 RUNNING", CENTER_MODE);  
     printf("Task2 Running\n\r");  
     
     while(true) {
     //float i=0;
-    //led2 = !led2;
+    led2 = !led2;
     bluetooth.printf("Hello World !\r\n");
     Thread::wait(1000);
     //bluetooth.printf("This program runs since %f seconds.\r\n", i++);       
 }
-}
+}*/
 
-void semaphore_test(void const *name)
+/*void btn_int(){
+    
+    one_slot.release();
+    }*/
+
+/*void semaphore_test(void const *name)
 {
     while (true) {
-        one_slot.acquire();
-        printf("%s\n\r", (const char *)name);
-        ThisThread::sleep_for(1000);
+        one_slot.wait();
+        
+        printf("%s acquires semaphore\n\r", (const char *)name);
+        Thread::wait(1000);
         one_slot.release();
+        printf("%s releases semaphore\n\r", (const char *)name);
     }
-}
+}*/
  
 int main() {
     printf("We are in main.\n\r");
     
     thread1.set_priority(osPriorityHigh);
     thread2.set_priority(osPriorityNormal);
-    
+    //thread3.set_priority(osPriorityNormal);
+    //thread4.set_priority(osPriorityLow);
 
-    thread1.start(thread1_function);       // Starting the processes
-    thread2.start(thread2_function);
+    thread1.start(voltage_function, (void *)"Thread 1");       // Starting the processes
+    thread2.start(voltage_function, (void *)"Thread 2");
     
-    thread3.start(test_thread, (void *)"Thread 3");
-    thread4.start(test_thread, (void *)"Thread 4");
+    //button.rise(&btn_int);
+    //thread3.start(semaphore_test, (void *)"Thread 3");
+    //thread4.start(semaphore_test, (void *)"Thread 4");
     
     thread1.join();
     thread2.join();