ESP32: ESP32_xSemaphoreBinary.ino

File ESP32_xSemaphoreBinary.ino, 779 bytes (added by krit, 3 years ago)
Line 
1#include <Arduino.h>
2
3SemaphoreHandle_t sem_boss;
4
5void employee_talk(){
6  Serial.println("Employee working...");
7}
8
9void boss(void *pvParameters){
10  int count=0;
11  while(true){
12    Serial.print(count++);
13    Serial.println(" Boss giveing the single...");
14    xSemaphoreGive(sem_boss);
15    Serial.println("Boss finished giveing the single...\n");
16    vTaskDelay(5000);
17  }
18}
19
20void employee(void *pvParameters){
21  while(true){
22    if ( xSemaphoreTake(sem_boss, portMAX_DELAY) ){
23      employee_talk();
24      Serial.println("Employee worked...Done\r\n");
25    }
26  }
27}
28
29void setup() {
30  Serial.begin(115200);
31  sem_boss = xSemaphoreCreateBinary();
32  xTaskCreate(boss, "boss",         1024, NULL, 3, NULL);
33  xTaskCreate(employee, "employee", 1024, NULL, 2, NULL);
34}
35
36void loop() { }