# Making Led blink and  stop on arduino uno

**URL:** <https://forums.freertos.org/t/making-led-blink-and-stop-on-arduino-uno/7137>\
**Category:** Kernel\
**Created:** [April 14, 2018, 3:31pm UTC](https://forums.freertos.org/t/making-led-blink-and-stop-on-arduino-uno/7137 "2018-04-14T15:31:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [April 14, 2018, 3:31pm UTC](https://forums.freertos.org/t/making-led-blink-and-stop-on-arduino-uno/7137/1 "2018-04-14T15:31:20Z")

</div>

**[ose](https://sourceforge.net/u/ose/)** wrote on [Saturday, April 14, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/37b663d0/#25a4):

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

```auto
#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);
  }
}

```

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [April 14, 2018, 4:35pm UTC](https://forums.freertos.org/t/making-led-blink-and-stop-on-arduino-uno/7137/2 "2018-04-14T16:35:55Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Saturday, April 14, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/37b663d0/#677d):

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

```auto
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)

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [April 15, 2018, 12:04pm UTC](https://forums.freertos.org/t/making-led-blink-and-stop-on-arduino-uno/7137/3 "2018-04-15T12:04:41Z")

</div>

**[ose](https://sourceforge.net/u/ose/)** wrote on [Sunday, April 15, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/37b663d0/#4efe):

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [April 15, 2018, 12:06pm UTC](https://forums.freertos.org/t/making-led-blink-and-stop-on-arduino-uno/7137/4 "2018-04-15T12:06:02Z")

</div>

**[ose](https://sourceforge.net/u/ose/)** wrote on [Sunday, April 15, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/37b663d0/#677d/083c):

Thank You very much
