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

Gremsy liked Gremsy's profile
Mar 12
DIY Robocars via Twitter
RT @chr1sa: Donkeycar 4.4 released with tons of new features, including path learning (useful with GPS outdoors), better Web and Lidar supp…
Nov 27, 2022
DIY Robocars via Twitter
RT @NXP: We are already biting our nails in anticipation of the #NXPCupEMEA challenge! 😉 Did you know there are great cash prizes to be won…
Nov 24, 2022
DIY Robocars via Twitter
RT @gclue_akira: レースまであと3日。今回のコースは激ムズかも。あと一歩 #jetracer https://t.co/GKcEjImQ3t
Nov 24, 2022
DIY Robocars via Twitter
UC Berkeley's DIY robocar program https://roar.berkeley.edu/
Nov 24, 2022
DIY Robocars via Twitter
RT @chr1sa: The next @DIYRobocars autonomous car race at @circuitlaunch will be on Sat, Dec 10. Thrills, spills and a Brazilian BBQ. Fun…
Nov 24, 2022
DIY Robocars via Twitter
RT @arthiak_tc: Donkey car platform ... Still training uses behavioral cloning #TCXpo #diyrobocar @OttawaAVGroup https://t.co/PHBYwlFlnE
Nov 20, 2022
DIY Robocars via Twitter
RT @emurmur77: Points for style. @donkeycar racing in @diyrobocars at @UCSDJacobs thanks @chr1sa for taking the video. https://t.co/Y2hMyj1…
Nov 20, 2022
DIY Robocars via Twitter
RT @SmallpixelCar: Going to @diyrobocars race at @UCSDJacobs https://t.co/Rrf9vDJ8TJ
Nov 8, 2022
DIY Robocars via Twitter
RT @SmallpixelCar: Race @diyrobocars at @UCSDJacobs thanks @chr1sa for taking the video. https://t.co/kK686Hb9Ej
Nov 8, 2022
DIY Robocars via Twitter
RT @PiWarsRobotics: Presenting: the Hacky Racers Robotic Racing Series in collaboration with #PiWars. Find out more and register your inter…
Oct 23, 2022
DIY Robocars via Twitter
RT @Hacky_Racers: There will be three classes at this event: A4, A2, and Hacky Racer! A4 and A2 are based around UK paper sizing and existi…
Oct 23, 2022
DIY Robocars via Twitter
Oct 23, 2022
DIY Robocars via Twitter
Oct 19, 2022
DIY Robocars via Twitter
Oct 18, 2022
DIY Robocars via Twitter
RT @NeaveEng: Calling all UK based folks interested in @diyrobocars, @f1tenth, @donkey_car, and similar robot racing competitions! @hacky_r…
Oct 13, 2022
More…