HobbyKing.com New Products Flash Sale
Reply
Thread Tools
Old Mar 28, 2013, 10:02 PM
Thermite + ice = Big boom.
boaterguy's Avatar
Canada, ON, Ottawa
Joined Apr 2009
2,380 Posts
Discussion
Ideas for quadcopter lights

I'm building a quad distribution board with an arduino for checking battery voltage and temperatures and flashing lights accordingly. But since I already have RGB LED strips on the thing (hobbyking ones), I figured I might as well be able to switch them on to some cool color changing sequence for at night.
I just don't have any ideas. I was thinking of having it start on red, slowly fade to green, and the to blue, and back to red. I would be able to do this with two colors, probably in a for loop, but how would I do it with three?
boaterguy is offline Find More Posts by boaterguy
Reply With Quote
Sign up now
to remove ads between posts
Old Mar 28, 2013, 10:23 PM
Registered User
Joined Oct 2012
224 Posts
i think you can use 12f675 for project, you will find very much on internet
fantasy1988 is offline Find More Posts by fantasy1988
Reply With Quote
Old Mar 28, 2013, 10:46 PM
Thermite + ice = Big boom.
boaterguy's Avatar
Canada, ON, Ottawa
Joined Apr 2009
2,380 Posts
I'm already set on the arduino, I have it here and I know how to do all of the code (and I have it written already). I did some research and figured out how to do it, but it uses a for loop, I have to have other code running at the same time so I can't get locked into a for loop to do it.
boaterguy is offline Find More Posts by boaterguy
Reply With Quote
Old Mar 29, 2013, 12:24 AM
User
Colorado
Joined Oct 2004
1,424 Posts
how to control two events instantaneously
rmteo is offline Find More Posts by rmteo
Reply With Quote
Old Mar 29, 2013, 10:20 AM
Dave the Rave
dmccormick001's Avatar
Joined Jun 2007
876 Posts
Do some research on PWM. The only way to "fade" an LED is to flash it on/off rapidly, you can't do it by reducing or controlling voltage like you would with a normal bulb. Pulse Width Modulation allows you to control the on and off cycle of the pulse, which makes the LED appear to be dimmer or brighter. It can also be accomplished with a simple loop by adjusting the pause time between the on and off (high/low) commands.
dmccormick001 is offline Find More Posts by dmccormick001
Reply With Quote
Old Mar 29, 2013, 11:33 AM
Thermite + ice = Big boom.
boaterguy's Avatar
Canada, ON, Ottawa
Joined Apr 2009
2,380 Posts
Yes, I am controlling them with PWM.
boaterguy is offline Find More Posts by boaterguy
Reply With Quote
Old Mar 29, 2013, 05:26 PM
KK Tri Flyer
mattcro's Avatar
United Kingdom, Scotland, Glasgow
Joined Feb 2012
346 Posts
You just need 1 PWM output per color, and a loop that cycles through all the tasks every few 10's of millisecs, or however fast you need to your LED fading/cycling.

You could use a timer interrupt (or the Arduino's millis() function) to regulate the loop speed to keep your PWM updates smooth. Before or after updating the PWM each loop, you can do the other things like checking battery voltage.

Code:
setup()
{
   //config ports
   //config timer to generate interrupt every x msec and set a flag
}

loop()
{
   //Wait until timer interrupt flag (or wait until millis() > previousMillis + delayTime)
   //check voltage and set alarm or LED
   //update PWM outputs according to some sequence
}
Some of the Arduino sketchbook samples deal with PWM output, colour cycling LEDs and similar, so have a look at them as a starting point for this kind of thing.

Regulating the loop speed using millis() is shown here http://arduino.cc/en/Tutorial/BlinkWithoutDelay
mattcro is offline Find More Posts by mattcro
Last edited by mattcro; Mar 29, 2013 at 05:41 PM.
Reply With Quote
Old Mar 29, 2013, 05:55 PM
Thermite + ice = Big boom.
boaterguy's Avatar
Canada, ON, Ottawa
Joined Apr 2009
2,380 Posts
Here's what I managed to come up with without a for loop, what do you guys think? How could I make it a little bit more professional?
Code:
  if ((pwmRead > 1800) && (battVoltage > 11.0)) //if switch is on
  {
    if (rgbLed [incLed] = 255)
    {
      if (incLed > 1)
      {
        incLed = 0;
      }
      else
      {
        incLed += 1;
      }
      if (decLed > 1)
      {
        decLed = 0;
      }
      else
      {
        decLed += 1;
      }
      rgbLed [incLed] += 1;
      rgbLed [decLed] -= 1;
      analogWrite (writeLed [incLed], rgbLed [incLed]);
      analogWrite (writeLed [decLed], rgbLed [decLed]);
boaterguy is offline Find More Posts by boaterguy
Reply With Quote
Old Mar 31, 2013, 08:21 PM
Registered User
United States, ID
Joined Sep 2011
593 Posts
Quote:
How could I make it a little bit more professional?
You could format your code better by getting rid of all the extra lines. Use increment (++) and decrement (--) operators instead of +=/-=.

Code:
if ((pwmRead > 1800) && (battVoltage > 11.0)){ //if switch is on
    if (rgbLed [incLed] = 255){
        if (incLed > 1){ incLed = 0;}
        else{ incLed += 1;}
        if (decLed > 1){ decLed = 0;}
        else{ decLed += 1;}
        rgbLed[incLed]++;
        rgbLed[decLed]--;
        analogWrite(writeLed[incLed], rgbLed[incLed]);
        analogWrite(writeLed[decLed], rgbLed[decLed]);
One line loops should be on one line. No extra spaces or lines except for readability. Open brackets should be on the loop or function line they are related to. Parameters should be right after functions (no spaces), no spaces between array names and index.

All the extra spaces and lines make your code look larger and more complicated than it really is. Spacing things out also leads to errors when you're cutting and pasting and moving things around. If it's right together then it's a lot harder to get it mixed up.

Other than that it looks fine and readable. You're missing a few close brackets unless I munged them.
jakestew is online now Find More Posts by jakestew
Reply With Quote
Old Mar 31, 2013, 10:19 PM
Thermite + ice = Big boom.
boaterguy's Avatar
Canada, ON, Ottawa
Joined Apr 2009
2,380 Posts
Thanks, I'm used to spreading out my code for the more complex operations, I'll shrink it down.
That's just a snippet of the code, not the whole thing, the brackets are in the real thing.
boaterguy is offline Find More Posts by boaterguy
Reply With Quote
Reply


Thread Tools

Similar Threads
Category Thread Thread Starter Forum Replies Last Post
Video Why it's a bad idea to fly a quadcopter indoors Mike_Then Multirotor Talk 2 Mar 01, 2013 08:56 PM
Sold PRICE DROP "Light Saber" quadcopter, For sale BNF or trade for naza + cash kicekilla Aircraft - Electric - Multirotor (FS/W) 4 Jun 27, 2012 01:45 PM
For Sale 2 Quadcopter frames for sell, free LED lights and ESC power boards terriwang Aircraft - Electric - Multirotor (FS/W) 11 Sep 11, 2011 03:53 AM
An idea for a very fast, light mini wing jms336 Foamies (Kits) 31 Sep 08, 2003 10:23 AM