Experimenting w/FreeRTOS
Dependencies: FreeRTOS mbed MMA7660 LM75B
main.cpp
- Committer:
- tkatolrnmcu
- Date:
- 2017-08-22
- Revision:
- 1:1990d6e600c2
- Parent:
- 0:ef389421b079
- Child:
- 2:4e4fa763799a
File content as of revision 1:1990d6e600c2:
#include "mbed.h" #include "FreeRTOS.h" #include "task.h" #include "C12832.h" #include "LM75B.h" DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); C12832 lcd(p5, p7, p6, p8, p11); LM75B sensor(p28,p27); void vHello(void *pvParameters); void vGbye(void *pvParameters); int main() { portBASE_TYPE task1rc; portBASE_TYPE task2rc; if (sensor.open()){ printf("LM75B temperature sensor detected, proceeding with program.\n"); } else { printf("LM75B sensor not detected!\n"); return; } task1rc = xTaskCreate(vHello, "HELLO", configMINIMAL_STACK_SIZE, (void*)"name1", configMAX_PRIORITIES-2, NULL); task2rc = xTaskCreate(vGbye, "BYE", configMINIMAL_STACK_SIZE, (void*)"name2", configMAX_PRIORITIES-1, NULL); vTaskStartScheduler(); if (task1rc == pdPASS){ led1 = 1; wait(0.5); led1 = 0; } else{ led1 = 0; } if (task2rc == pdPASS){ led2 = 1; wait(0.5); led2 = 0; } else{ led2 = 0; } for (;;){ led3 = 1; led4 = 1; wait(0.5); led3 = 0; led4 = 0; wait(0.5); }; } void vHello(void *pvParameters) { char *ptr = 0; ptr = (char *)pvParameters; for(;;) { printf("Hello %s!\n", ptr); printf("Current temperature: %s\n", (float)sensor.temp()); led1 = !led1; vTaskDelay(300); } } void vGbye(void *pvParameters) { char *ptr = 0; ptr = (char *)pvParameters; for(;;) { printf("Goodbye %s!\n", ptr); led2 = !led2; wait(0.5); vTaskDelay(300); } }