RGB LED fader with poweron-cycle


hey,

i want program code will, when arduino gets power, fades 3 rgb leds 0 255, fades white fourth 1 0 255 , lets rgb led cycle through rgb-space.

this got far.

code: [select]

// rgb led - automatic color cycling
//
// matthew l beckler
// matthew @ mbeckler dot org

int redpin = 13;
int bluepin = 12;
int greenpin = 11;
int whitepin = 7;

int redval;
int greenval;
int blueval;
int whiteval;
int startupstat;
const int fadeamount = 10;
const int fadewhite = 5;

void setup()
{
 redval = 0;
 greenval = 0;
 blueval = 0;
 whiteval = 10;
 startupstat = 0;
 update();
}

// function updates led outputs.
void update()
{
 analogwrite(redpin, redval);
 analogwrite(greenpin, greenval);
 analogwrite(bluepin, blueval);
 analogwrite(whitepin, whiteval);
}

// function updates 1 of color variables
// either getting brighter or getting dimmer.
// updates outputs , delays 10 milliseconds.
void color_morph(int* value, int get_brighter)
{
 for (int = 0; < 255; i++)
 {
   if (get_brighter)
     (*value)--;
   else
     (*value)++;
     
   update();
   delay(10);
 }
}

void loop()
{
 if (startupstat == 0) {
   startupstat = 0;
   redval = redval + fadeamount;
   greenval = greenval + fadeamount;
   blueval = greenval + fadeamount;
   if (blueval == 255) {
     startupstat = 1;
   }
   update();
   delay(10);
 }
 if (startupstat == 1) {
   whiteval = whiteval + fadewhite;
   if (whiteval = 255) {
    startupstat = 2;
   }
   update();
   delay(10);
 }  
 if (startupstat == 2) {
 // start out @ black (all off)
 color_morph(&redval,   1); // transition red
 color_morph(&greenval, 1); // transition yellow
 color_morph(&redval,   0); // transition green
 color_morph(&blueval,  1); // transition aqua
 color_morph(&redval,   1); // transition white
 color_morph(&greenval, 0); // transition violet
 color_morph(&redval,   0); // transition blue
 color_morph(&blueval,  0); // transition black (all off)
 }
}


i got problem fades in rgb led (step 1) repeats 1 step on , over. won't jump next step.

can please me this? i'm clueless makes ignore simple "if".

edit: if (whiteval = 255)   <----- = ??

use  
code: [select]
for (int = 0; < 256; i++)
or use
code: [select]
if (blueval >= 254) {
and
code: [select]
if (whiteval >= 254) {


Arduino Forum > Using Arduino > Project Guidance > RGB LED fader with poweron-cycle


arduino

Comments

Popular posts from this blog

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums

Multithumb configuration params not working? - Joomla! Forum - community, help and support