How To light off the Led Strip / How to accelerate the Led Strip

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
julia753
 
Posts: 1
Joined: Mon Dec 03, 2012 7:03 pm

How To light off the Led Strip / How to accelerate the Led Strip

Post by julia753 »

Hello everybody, I'm Julia from France and I have a project to make for school.
I bought an adafruit LPD8806 but I have sme problem with it and three days that I work on it !

I use a light sensor and I want to use the val for know if I must light on or not my ledstrip.

What I want is


if val > 600

Led Strip off,

else if val < 600 & val > 400

Led Strip on - speed 1

else if val < 400

Led strip - speed 2




I use only red led in the stripe so I made :


Code: Select all


//    ---------     Led Strip  CODE

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

// Number of RGB LEDs in strand:
int nLEDs = 64;

// Chose 2 pins for output; can be any valid output pins:
int dataPin  = 2;
int clockPin = 3;

LPD8806 strip = LPD8806(64, dataPin, clockPin);


//  -------- End of the led strip   CODE


int val = 0;  


void setup() {
  Serial.begin(9600);  
  pinMode(LED, OUTPUT); // LED is as an OUTPUT
  
  // --------  Led strip code
  
    // Start up the LED strip
  strip.begin();

  // Update the strip, to start they are all 'off'
  strip.show();
  
  // ------ End of the LED Strip
  
}

void loop() {
    
  val = analogRead(0); 
  
if (val > 600)
{
  
  // Here I want to set off the ledstripe 
}
else  if (val<600 && val > 400)
{
  // -------  LED Stripe Code
  
  
  // Send a simple pixel chase in...
  colorChase(strip.Color(127,   0,   0), 50); // Red

  // Fill the entire strip with...
  colorWipe(strip.Color(127,   0,   0), 50);  // Red

  
  // ------- END OF THE LED STRIPE CODE 
  }
else  if (val<400)
{

  // Here I want to accelerate the LED stripe

  
    Serial.println("RUBAN");

  
  }

  
 



  Serial.println("Capteur 1   ");
  Serial.println(val);

  delay(1000);

}


//------- LED STRIPE CODE 

void rainbow(uint8_t wait) {
  int i, j;
   
  for (j=0; j < 384; j++) {     // 3 cycles of all 384 colors in the wheel
    for (i=0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel( (i + j) % 384));
    }  
    strip.show();   // write all the pixels out
    delay(wait);
  }
}

// Slightly different, this one makes the rainbow wheel equally distributed 
// along the chain
void rainbowCycle(uint8_t wait) {
  uint16_t i, j;
  
  for (j=0; j < 384 * 5; j++) {     // 5 cycles of all 384 colors in the wheel
    for (i=0; i < strip.numPixels(); i++) {
      // tricky math! we use each pixel as a fraction of the full 384-color wheel
      // (thats the i / strip.numPixels() part)
      // Then add in j which makes the colors go around per pixel
      // the % 384 is to make the wheel cycle around
      strip.setPixelColor(i, Wheel( ((i * 384 / strip.numPixels()) + j) % 384) );
    }  
    strip.show();   // write all the pixels out
    delay(wait);
  }
}

// Fill the dots progressively along the strip.
void colorWipe(uint32_t c, uint8_t wait) {
  int i;

  for (i=0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
  }
}

// Chase one dot down the full strip.
void colorChase(uint32_t c, uint8_t wait) {
  int i;

  // Start by turning all pixels off:
  for(i=0; i<strip.numPixels(); i++) strip.setPixelColor(i, 0);

  // Then display one pixel at a time:
  for(i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c); // Set new pixel 'on'
    strip.show();              // Refresh LED states
    strip.setPixelColor(i, 0); // Erase pixel, but don't refresh!
    delay(wait);
  }

  strip.show(); // Refresh to turn off last pixel
}

/* Helper functions */

//Input a value 0 to 384 to get a color value.
//The colours are a transition r - g -b - back to r

uint32_t Wheel(uint16_t WheelPos)
{
  byte r, g, b;
  switch(WheelPos / 128)
  {
    case 0:
      r = 127 - WheelPos % 128;   //Red down
      g = WheelPos % 128;      // Green up
      b = 0;                  //blue off
      break; 
    case 1:
      g = 127 - WheelPos % 128;  //green down
      b = WheelPos % 128;      //blue up
      r = 0;                  //red off
      break; 
    case 2:
      b = 127 - WheelPos % 128;  //blue down 
      r = WheelPos % 128;      //red up
      g = 0;                  //green off
      break; 
  }
  return(strip.Color(r,g,b));
}

//------- END OF THE LED STRIPE CODE 





Thanks for the help !!

Julia

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: How To light off the Led Strip / How to accelerate the Led Strip

Post by adafruit_support_bill »

if val > 600

Led Strip off,
To turn the strip off, just do a colorWipe with 'black':

Code: Select all

     colorWipe(strip.Color(0,   0,   0), 50);  // Black
else if val < 600 & val > 400

Led Strip on - speed 1

else if val < 400

Led strip - speed 2
To change the speed of the strip, change the delay parameter (the last one). A shorter delay will make it go faster.

Code: Select all

    colorChase(strip.Color(127,   0,   0), 50); // Red - Slow

    colorChase(strip.Color(127,   0,   0), 10); // Red - Fast!

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

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