Same as freertos_bluetooth but now with FreeRTOS v_8.2.1
Dependencies: mbed m3pi FreeRTOS_V8_2_1_LPC1768
Diff: main.cpp
- Revision:
- 4:33929b1afb80
- Parent:
- 3:d577dbef65a2
- Child:
- 5:97a449a1e05f
--- a/main.cpp Sun Sep 13 11:33:05 2015 +0000 +++ b/main.cpp Wed Dec 05 17:56:16 2018 +0000 @@ -5,34 +5,64 @@ #include "mbed.h" #include "FreeRTOS.h" #include "task.h" +#include "m3pi.h" + +m3pi m3pi; DigitalOut led1(LED1); DigitalOut led2(LED2); -void Task1 (void* pvParameters) +Serial rn41(p28,p27); // Serial rn41(p9,p10); + + +const portTickType xDelay = 100 / portTICK_RATE_MS; + +const float fVref = 4.0; + + +void TaskBluetooth (void* pvParameters) { (void) pvParameters; // Just to stop compiler warnings. + + char *cBufferBT; + + rn41.baud(115200); + led1 = 1; + led2 = 1; + for (;;) { + + if(m3pi.battery() < fVref) { + m3pi.cls(); + m3pi.locate(0,0); + m3pi.print("Low Pwr!", 8); + } + else{ + m3pi.cls(); + m3pi.locate(0,0); + m3pi.print("BT Task", 8); + } + + if (rn41.readable()) { // When BT is readable + + sprintf(cBufferBT, "%d", rn41.getc()); // Reads Bluetooth + m3pi.locate(0,1); // Prints the received message on the LCD + m3pi.print(cBufferBT, 8); + + rn41.putc(6); // Send message to the BT terminal + led2 = !led2; + } + led1 = !led1; - printf("Task1\n"); - vTaskDelay(500); + vTaskDelay(xDelay); } } -void Task2 (void* pvParameters) -{ - (void) pvParameters; // Just to stop compiler warnings. - for (;;) { - led2= !led2; - printf("Task2\n"); - vTaskDelay(5000); - } -} + int main (void) { - xTaskCreate( Task1, ( signed char * ) "Task1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, ( xTaskHandle * ) NULL ); - xTaskCreate( Task2, ( signed char * ) "Task2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, ( xTaskHandle * ) NULL ); + xTaskCreate( TaskBluetooth, ( signed char * ) "TaskBluetooth", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, ( xTaskHandle * ) NULL ); vTaskStartScheduler(); //should never get here printf("ERORR: vTaskStartScheduler returned!");