volatile uint32_t inventory = 100;
volatile uint32_t retailCount = 10;
void retailTask(void* pvParam)
{
while(true)
{
uint32_t inv = inventory;
for(int i=0; i<random(10, 100); i++)
vTaskDelay(pdMS_TO_TICKS(i));
if(inventory > 0)
{
inventory = inv - 1;
retailCount++;
}
}
vTaskDelay(10);
}
void showTask(void* pvParam)
{
while(true)
{
printf("Inventory: %d\n", inventory);
printf(" Retail : %d\n", retailCount);
if (inventory == 0 ) {
printf("\n-----SALES SUMMARY-----\n");
printf(" Total Sales: %d\n\n", retailCount);
}
vTaskDelay(pdMS_TO_TICKS(100));
}
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
xTaskCreate(retailTask, "Online Channel", 1024 * 4, NULL, 1, NULL);
xTaskCreate(showTask, "Display Inventory", 1024 * 4, NULL, 1, NULL);
}
void loop() {
// put your main code here, to run repeatedly:
}