Blinking an external LED

Firmware/software/electronics/mechanics
Post Reply
bpospeck
Beginner
Posts: 14
Joined: Tue Jan 10, 2017 4:42 am

Blinking an external LED

Post by bpospeck »

I'm trying to implement external functionality, starting with something as simple as flashing an LED on and off repeatedly. I'm at the point where I can setup a file that will turn on an LED from one of the GPIO ports. I've even been able to use parameters associated with the LED to turn it on and off with a python script.

For some reason I'm having issues trying to figure out how I can get that external LED to blink on and off repeatedly by itself. I assume I'm likely missing something simple. I appreciate any help!
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Blinking an external LED

Post by tobias »

I guess you started out with something like the deck howto.

Next step to get something blinking would be to create a task which runs within the deck. E.g. the vl53l0x deck creates a task and then runs it periodically.

So something similar to this:

Code: Select all

#include "FreeRTOS.h"
#include "task.h"

//...

static bool isInit;

//...

void yourInit(DeckInfo* info)
{
  if (isInit)
    return;

  xTaskCreate(yourTask, "yourTask", configMINIMAL_STACK_SIZE, NULL, /*priority*/ 1, NULL);
    
  isInit = true;
}

void yourTask(void* arg)
{
  systemWaitStart();
  TickType_t xLastWakeTime;

  while (1) {
    xLastWakeTime = xTaskGetTickCount();

    /* Your code */

    vTaskDelayUntil(&xLastWakeTime, M2T(PERIOD_SLEEP_TIME_IN_MS));
  }
}

//...
bpospeck
Beginner
Posts: 14
Joined: Tue Jan 10, 2017 4:42 am

Re: Blinking an external LED

Post by bpospeck »

That's exactly what I was looking for, thanks! I got it to work how I wanted.

I just want to check my understanding of this code before calling this solved. I did have a couple of questions regarding the "xTaskCreate" function though:
1) What does it do beyond just a normal function declaration? I assume it does some sort of setup and deals with priority levels, but what exactly?
2) I'm also curious what the 2 NULL arguments are for. What type of arguments might otherwise go there?

Now for the "yourTask" itself. I assume the systemWaitStart() just keeps the task from executing until the Crazyflie is on and finished with any initialization processes. The xLastWakeTime looks to me like it keeps track of when the while loop last started so that when it reaches the end of the loop, it can use vTaskDelayUntil to keep the loop from restarting until it's the specificed milliseconds after that xLastWakeTime.

I am curious as to why the argument given to yourTask is "void* arg". Are there certain tasks in the Crazyflie that need to be passed different types of pointers? Or any pointers at all?

Alright, I think that covers everything, thanks again tobias!
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Blinking an external LED

Post by tobias »

You pretty much interpreted it just how it is. FreeRTOS is well documented so you will be better of reading it from there, then I writing something which is wrong, e.g. xTaskCreate.

The task priorities can be found in config.h and if not critical priority 1 is good to use.
bpospeck
Beginner
Posts: 14
Joined: Tue Jan 10, 2017 4:42 am

Re: Blinking an external LED

Post by bpospeck »

Thanks so much for your help! Now the plan is to implement some functionality with external motors. I'm sure I'll have another post up when I run into complications there and have more questions. :lol:
Post Reply