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

Committer:
hunter64288
Date:
Sun Jan 17 19:51:15 2021 +0000
Revision:
12:441ee5b1cf71
Parent:
11:0309bef74ba8
Child:
13:d21f6477ba19
Bluetooth working + 2 tasks; NEXT ---> Semaphores , Queues , Timer on Tasks (??)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 1:491820ee784d 1 #include "mbed.h"
mbed_official 11:0309bef74ba8 2 #include "rtos.h"
hunter64288 12:441ee5b1cf71 3 #include "LCD_DISCO_F429ZI.h"
hunter64288 12:441ee5b1cf71 4 //#include <AnalogIn.h>
hunter64288 12:441ee5b1cf71 5
hunter64288 12:441ee5b1cf71 6 //float message_t
hunter64288 12:441ee5b1cf71 7 //MemoryPool<message_t, 10> mpool;
hunter64288 12:441ee5b1cf71 8 //Queue<message_t, > queue;
hunter64288 12:441ee5b1cf71 9
hunter64288 12:441ee5b1cf71 10 Serial bluetooth(PA_9, PA_10);//Tx, Rx
hunter64288 12:441ee5b1cf71 11 AnalogIn ain(PA_0); //potentiometer
hunter64288 12:441ee5b1cf71 12
emilmont 1:491820ee784d 13 DigitalOut led1(LED1);
emilmont 1:491820ee784d 14 DigitalOut led2(LED2);
hunter64288 12:441ee5b1cf71 15 //DigitalIn btn1(PA_0); //Button on your Nucleo Board
hunter64288 12:441ee5b1cf71 16
hunter64288 12:441ee5b1cf71 17 LCD_DISCO_F429ZI lcd;
hunter64288 12:441ee5b1cf71 18 Thread thread1; //thread(osPriority osPriorityNormal)
hunter64288 12:441ee5b1cf71 19 Thread thread2;
emilmont 1:491820ee784d 20
hunter64288 12:441ee5b1cf71 21 void thread1_function() {
hunter64288 12:441ee5b1cf71 22 lcd.Clear(LCD_COLOR_WHITE);
hunter64288 12:441ee5b1cf71 23 lcd.DisplayStringAt(0, LINE(1), (uint8_t *)"TASK1 RUNNING", CENTER_MODE);
hunter64288 12:441ee5b1cf71 24 printf("Task1 Running\n\r");
hunter64288 12:441ee5b1cf71 25 //DigitalOut led1(LED1);
hunter64288 12:441ee5b1cf71 26 //led1 = !led1;
hunter64288 12:441ee5b1cf71 27
hunter64288 12:441ee5b1cf71 28 float samples[10];
hunter64288 12:441ee5b1cf71 29 float volt_value[10];
hunter64288 12:441ee5b1cf71 30 while(1) {
hunter64288 12:441ee5b1cf71 31 for(int i=0; i<10; i++) {
hunter64288 12:441ee5b1cf71 32 //ain.set_reference_voltage(3.0);
hunter64288 12:441ee5b1cf71 33 samples[i] = ain.read()*3;
hunter64288 12:441ee5b1cf71 34 //volt_value[i] = (((float)samples[i])/255.0)*3.0;
hunter64288 12:441ee5b1cf71 35 wait(0.001f);
emilmont 1:491820ee784d 36 }
hunter64288 12:441ee5b1cf71 37
hunter64288 12:441ee5b1cf71 38 bluetooth.printf("Results:\n");
hunter64288 12:441ee5b1cf71 39 for(int i=0; i<10; i++) {
hunter64288 12:441ee5b1cf71 40 bluetooth.printf("%d = , %f\n", i, samples[i]);
hunter64288 12:441ee5b1cf71 41 }
hunter64288 12:441ee5b1cf71 42 Thread::wait(1000);
hunter64288 12:441ee5b1cf71 43 }
hunter64288 12:441ee5b1cf71 44 }
hunter64288 12:441ee5b1cf71 45 void thread2_function() {
hunter64288 12:441ee5b1cf71 46 lcd.DisplayStringAt(0, LINE(2), (uint8_t *)"TASK2 RUNNING", CENTER_MODE);
hunter64288 12:441ee5b1cf71 47 printf("Task2 Running\n\r");
hunter64288 12:441ee5b1cf71 48
hunter64288 12:441ee5b1cf71 49 while(true) {
hunter64288 12:441ee5b1cf71 50 //float i=0;
hunter64288 12:441ee5b1cf71 51 //led2 = !led2;
hunter64288 12:441ee5b1cf71 52 bluetooth.printf("Hello World !\r\n");
hunter64288 12:441ee5b1cf71 53 Thread::wait(1000);
hunter64288 12:441ee5b1cf71 54 //bluetooth.printf("This program runs since %f seconds.\r\n", i++);
hunter64288 12:441ee5b1cf71 55
hunter64288 12:441ee5b1cf71 56
hunter64288 12:441ee5b1cf71 57 }
emilmont 1:491820ee784d 58 }
emilmont 1:491820ee784d 59
emilmont 1:491820ee784d 60 int main() {
hunter64288 12:441ee5b1cf71 61 printf("We are in main.\n\r");
hunter64288 12:441ee5b1cf71 62
hunter64288 12:441ee5b1cf71 63 thread1.set_priority(osPriorityHigh);
hunter64288 12:441ee5b1cf71 64 thread2.set_priority(osPriorityNormal);
hunter64288 12:441ee5b1cf71 65
hunter64288 12:441ee5b1cf71 66 thread1.start(thread1_function); // Starting the processes
hunter64288 12:441ee5b1cf71 67 thread2.start(thread2_function);
emilmont 1:491820ee784d 68
hunter64288 12:441ee5b1cf71 69 thread1.join();
hunter64288 12:441ee5b1cf71 70 thread2.join();
hunter64288 12:441ee5b1cf71 71
hunter64288 12:441ee5b1cf71 72 //wait for threads to complete
hunter64288 12:441ee5b1cf71 73 printf("The end of main.\n\r");
emilmont 1:491820ee784d 74 }
hunter64288 12:441ee5b1cf71 75
hunter64288 12:441ee5b1cf71 76