Some pattern blinking leds

After reading some topics about this and reading new code, I created some pattern of blinking leds.

I also modified a little code of leds.pde, so it easy to extent and add more. Now it can blink depending on fly mode.

I write code of showing leds as:

static void control_leds(byte ledbits) {
    digitalWrite(COPTER_LED_1, bitRead(ledbits, 0));
    digitalWrite(COPTER_LED_2, bitRead(ledbits, 1));
    digitalWrite(COPTER_LED_3, bitRead(ledbits, 2));
    digitalWrite(COPTER_LED_4, bitRead(ledbits, 3));
    digitalWrite(COPTER_LED_5, bitRead(ledbits, 4));
    digitalWrite(COPTER_LED_6, bitRead(ledbits, 5));
    digitalWrite(COPTER_LED_7, bitRead(ledbits, 6));
    digitalWrite(COPTER_LED_8, bitRead(ledbits, 7));
}

So we can turn on/off just by using bits as B10101010 to turn off 1, 3, 5, 7 and on 2, 4, 6, 8.

My patterns for 4 modes:

//stablize mode

//circle mode

//loiter mode

and //Althold mode

Function to control blinking leds is

static void show_leds(void) {
    switch(control_mode)
    {
      case STABILIZE:
          leds_on_mode_1();
          break;
 
      case ALT_HOLD:
          leds_on_mode_4();
          break;
 
      case AUTO:
          break;
 
      case CIRCLE:
          leds_on_mode_2();
          break;
 
      case LOITER:
          leds_on_mode_3();
          break;
 
      case POSITION:
          break;
 
      case GUIDED:
          break;
 
      case LAND:
          break;
 
      case RTL:
          break;
    }
}

And to make it works, just comments the line of code copter_leds_on and add new function to control it in static void update_copter_leds(void)

...

            } else if ( !bitRead(g.copter_leds_mode, 5 ) ) {
                //copter_leds_on();                                                                       //if motors are armed, battery level OK, all motor leds ON
                show_leds();

...

Hope this can be helpful and enjoy with it.

I am having only a problem with controlling the leds.

When I turn led 2, and off others, the led 1 also on. Do not know why, test with ULN2803 only with 5v in, it works and with board only, it also worked well.

Anyone has this problem?

Thanks,

Duy

leds.pde

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • I plan adding led stripes to my copter next week and because it'll be my first code modification your post has perfect timing :)
    Where do you connect stripes (well, actually 2803)?

    I also plan to add a buzzer so I can invoke it remotely. This will greatly help looking for a quad in high grass.
This reply was deleted.

Activity