Making Led blink and stop on arduino uno

ose wrote on Saturday, April 14, 2018:

Hi, I am new to freertos and i have been trying out some stuffs . I have been able to make the led blink on my ardunio uno board but I am trying to make it blink for sometime andthen stop but i dont know how to implement that on freertos.
I know i need a for loop to indicate how mnay times it should blink but how to implement that on freertos is where i am stucked at.

Can someone please advice me on how to go about that?
Thank you.

Hers is an exmaple of the code making the led blink normally witout stopping

#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"

#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>

static void TaskBlinkyellowLED(void* pvParameters);

//-----------------------------------------------------------

int main()
{

  xTaskCreate(TaskBlinkyellowLED, (const portCHAR*) "yellowLED", 256, NULL, 3, NULL);

  vTaskStartScheduler();

  for (;;)
    ;;

  return 0;
}

//-----------------------------------------------------------






// Main yellow LED Flash
static void TaskBlinkyellowLED(void* pvParameters)
{
  // set pin 5 of PORTB for output
  DDRB |= _BV(DDB5);

  TickType_t xLastWakeTime = xTaskGetTickCount();
  while (true)
  {

		  // LED on
    PORTB |= _BV(PORTB5);
    vTaskDelayUntil(&xLastWakeTime, (1000/ portTICK_PERIOD_MS));

    // LED off
    PORTB &= ~_BV(PORTB5);
    vTaskDelayUntil(&xLastWakeTime, (1000 / portTICK_PERIOD_MS));
  }


  vTaskDelete(NULL);
}

//-----------------------------------------------------------

void vApplicationStackOverflowHook(TaskHandle_t xTask, portCHAR* pcTaskName)
{
  // main LED on
  DDRB |= _BV(DDB5);
  PORTB |= _BV(PORTB5);

  // die
  while (true)
  {
    PORTB |= _BV(PORTB5);
    _delay_ms(250);
    PORTB &= ~_BV(PORTB5);
    _delay_ms(250);
  }
}

rtel wrote on Saturday, April 14, 2018:

Perhaps more of a C question than a FreeRTOS question…can you just replace the while() looop with a for loop?

static void TaskBlinkyellowLED(void* pvParameters)
{
int x;

  // set pin 5 of PORTB for output
  DDRB |= _BV(DDB5);

  TickType_t xLastWakeTime = xTaskGetTickCount();
  for( x = 0; x < 10; x++ )
  {

          // LED on
    PORTB |= _BV(PORTB5);
    vTaskDelayUntil(&xLastWakeTime, (1000/ portTICK_PERIOD_MS));

    // LED off
    PORTB &= ~_BV(PORTB5);
    vTaskDelayUntil(&xLastWakeTime, (1000 / portTICK_PERIOD_MS));
  }

  vTaskDelete(NULL);
}

Or if you want to have fun - use an autoreloading software timer that has a callback function that:

  1. Toggles the LED.
  2. Counts the number of times it has executed, and when it has executed the required number of times, stops itself.

:o)

ose wrote on Sunday, April 15, 2018:

ose wrote on Sunday, April 15, 2018:

Thank You very much