LPD8806 timing question

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
ZapBranigan
 
Posts: 16
Joined: Fri May 16, 2014 1:27 am

LPD8806 timing question

Post by ZapBranigan »

Hi all, I'm pretty new to programming so please forgive me if this is super obvious. I'm working on a sketch that will fade between 2 colors using a map function. I'm happy with the fade part, but I'd like to build in a delay such that the fade will pause once the max/min values have been reached. The delay I currently have written only controls the speed of the fade itself. Any suggestions?

Code: Select all

#include "LPD8806.h"
#include "SPI.h"


LPD8806 strip = LPD8806(160);


void setup() {
  // Pink
#define COLOR1_R 127
#define COLOR1_G 1
#define COLOR1_B 25
// Aqua
#define COLOR2_R 0
#define COLOR2_G 93
#define COLOR2_B 66

#define top = 100; // maximum value of counter

  // Start up the LED strip
  strip.begin();

  // Update the strip, to start they are all 'off'
  strip.show();
}


void loop() {
int r,g,b;
uint16_t i, j;
for (j=0; j < 40; j++) {
r = map(j, 0, 40, COLOR1_R, COLOR2_R);
g = map(j, 0, 40, COLOR1_G, COLOR2_G);
b = map(j, 0, 40, COLOR1_B, COLOR2_B);

for (i=0; i < 160; i++) { 
strip.setPixelColor(i,(strip.Color(r,g,b) ));
} 

strip.show(); // write all the pixels out
delay(300);
}
for (j=0; j < 40; j++) {
r = map(j, 0, 40, COLOR2_R, COLOR1_R);
g = map(j, 0, 40, COLOR2_G, COLOR1_G);
b = map(j, 0, 40, COLOR2_B, COLOR1_B);

for (i=0; i < 160; i++) { 
strip.setPixelColor(i,(strip.Color(r,g,b) ));
} 

strip.show(); // write all the pixels out
delay(300);
}

}

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: LPD8806 timing question

Post by adafruit_support_rick »

Like this?

Code: Select all

#include "LPD8806.h"
#include "SPI.h"


LPD8806 strip = LPD8806(160);


void setup() {
  // Pink
#define COLOR1_R 127
#define COLOR1_G 1
#define COLOR1_B 25
  // Aqua
#define COLOR2_R 0
#define COLOR2_G 93
#define COLOR2_B 66

#define top = 100; // maximum value of counter

  // Start up the LED strip
  strip.begin();

  // Update the strip, to start they are all 'off'
  strip.show();
}


void loop() {
  int r,g,b;
  uint16_t i, j;
  for (j=0; j < 40; j++) {
    r = map(j, 0, 40, COLOR1_R, COLOR2_R);
    g = map(j, 0, 40, COLOR1_G, COLOR2_G);
    b = map(j, 0, 40, COLOR1_B, COLOR2_B);

    for (i=0; i < 160; i++) { 
      strip.setPixelColor(i,(strip.Color(r,g,b) ));
    } 

    strip.show(); // write all the pixels out
    delay(300);
  }
  
  delay(1000); //pause after max values reached
  
  for (j=0; j < 40; j++) {
    r = map(j, 0, 40, COLOR2_R, COLOR1_R);
    g = map(j, 0, 40, COLOR2_G, COLOR1_G);
    b = map(j, 0, 40, COLOR2_B, COLOR1_B);

    for (i=0; i < 160; i++) { 
      strip.setPixelColor(i,(strip.Color(r,g,b) ));
    } 

    strip.show(); // write all the pixels out
    delay(300);
  }
  
  delay(1000); //pause after min values reached
  
}

User avatar
ZapBranigan
 
Posts: 16
Joined: Fri May 16, 2014 1:27 am

Re: LPD8806 timing question

Post by ZapBranigan »

That is just the thing. Thank you! I'm a bit sheepish that I didn't try that. The next thing I'd like to try is to be able to specify a number of cycles for the loop to run, after which I'd like to change up the colors. Any suggestions?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: LPD8806 timing question

Post by adafruit_support_rick »

What I would do is to take the loop() function and change the name to something else, like 'colorLoop'. Then, write a new loop function that calls colorLoop some number of times with COLOR1 and COLOR2. After that, call colorLoop some number of times with COLOR3 and COLOR4:

Code: Select all

#include "LPD8806.h"
#include "SPI.h"


LPD8806 strip = LPD8806(160);

  // Pink
#define COLOR1_R 127
#define COLOR1_G 1
#define COLOR1_B 25
  // Aqua
#define COLOR2_R 0
#define COLOR2_G 93
#define COLOR2_B 66
  // Red
#define COLOR3_R 255
#define COLOR3_G 0
#define COLOR3_B 0
  // Green
#define COLOR4_R 0
#define COLOR4_G 255
#define COLOR4_B 0

#define top = 100; // maximum value of counter


void setup() {

  // Start up the LED strip
  strip.begin();

  // Update the strip, to start they are all 'off'
  strip.show();
}


void loop()
{
  int i;
 for (i = 0; i < 10; i++)
 {
   colorLoop(COLOR1_R, COLOR1_G, COLOR1_B, COLOR2_R, COLOR2_G, COLOR2_B);
 }
  
 for (i = 0; i < 10; i++)
 {
   colorLoop(COLOR3_R, COLOR3_G, COLOR3_B, COLOR4_R, COLOR4_G, COLOR4_B);
 }
}

void colorLoop(uint8_t c1_r, uint8_t c1_g, uint8_t c1_b, uint8_t c2_r, uint8_t c2_g, uint8_t c2_b) {
  int r,g,b;
  uint16_t i, j;
  for (j=0; j < 40; j++) {
    r = map(j, 0, 40, c1_r, c2_r);
    g = map(j, 0, 40, c1_g, c2_g);
    b = map(j, 0, 40, c1_b, c2_b);

    for (i=0; i < 160; i++) { 
      strip.setPixelColor(i,(strip.Color(r,g,b) ));
    } 

    strip.show(); // write all the pixels out
    delay(300);
  }
  
  delay(1000); //pause after max values reached
  
  for (j=0; j < 40; j++) {
    r = map(j, 0, 40, c2_r, c1_r);
    g = map(j, 0, 40, c2_g, c1_g);
    b = map(j, 0, 40, c2_b, c1_b);

    for (i=0; i < 160; i++) { 
      strip.setPixelColor(i,(strip.Color(r,g,b) ));
    } 

    strip.show(); // write all the pixels out
    delay(300);
  }
  
  delay(1000); //pause after min values reached
  
}

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”