Task not work

samanhamid wrote on Wednesday, November 06, 2019:

I started programming freertos.
i have Problem with thread

task work In this way :

void StartDefaultTask(void *argument)
{
for(;:wink:
{
HAL_GPIO_WritePin(GPIOG,GPIO_PIN_14,1);
osDelay(100);
HAL_GPIO_WritePin(GPIOG,GPIO_PIN_14,0);
osDelay(100);
}
}

when i use for
task not work :

void StartDefaultTask(void *argument)
{
for(;:wink:
{
for(int i=0;i>10;i++){
HAL_GPIO_WritePin(GPIOG,GPIO_PIN_14,1);
osDelay(100);
HAL_GPIO_WritePin(GPIOG,GPIO_PIN_14,0);
osDelay(100);
}
}

}

heinbali01 wrote on Wednesday, November 06, 2019:

Could it be that this statement is mistaken:

for(int i=0;i>10;i++){
}

It says: β€œwhile i is larger than 10” (i>10), which is not possible, because it was initialised to 0.

samanhamid wrote on Wednesday, November 06, 2019:

thank you for answer

but not work this cod

void StartTask02(void *argument){

int i=0;

for(;:wink:
{
for(i=1;i>100;i++){
HAL_GPIO_WritePin(GPIOG,GPIO_PIN_13,1);
osDelay(100);
HAL_GPIO_WritePin(GPIOG,GPIO_PIN_13,0);
osDelay(100);
}
}

}

or this:

void StartDefaultTask(void *argument)
{

 int i=0;

for(;:wink:
{

 while(i>100){
	 i++;
	HAL_GPIO_WritePin(GPIOG,GPIO_PIN_14,1);
osDelay(100);
	HAL_GPIO_WritePin(GPIOG,GPIO_PIN_14,0);
	osDelay(100);
 
 }

}

}

heinbali01 wrote on Wednesday, November 06, 2019:

Try this:

for(;;)
{
    for(i=1;i<100;i++){
        HAL_GPIO_WritePin(GPIOG,GPIO_PIN_13,1);
        osDelay(100);
        HAL_GPIO_WritePin(GPIOG,GPIO_PIN_13,0);
        osDelay(100);
    }
}

samanhamid wrote on Wednesday, November 06, 2019:

thank you very much
(while) worked but (for) not work

heinbali01 wrote on Thursday, November 07, 2019:

while worked but for (did) not work

A for-loop will also work, if you use the correct comparator.

These are two good examples:

for ( i = 0; i < 100; i++ ) { LedBlink(); } /*  0,  1,  2 .. 99 */
for ( i = 99; i >= 0; i-- ) { LedBlink(); } /* 99, 98, 97 .. 0 */

In these examples, the LED will not blink:

for ( i = 0; i > 100; i++ ) { LedBlink(); } /* no loops. */
for ( i = 99; i <= 0; i-- ) { LedBlink(); } /* no loops. */