Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: LPD8806 code on TEENSY 2.0++

  1. #1

    LPD8806 code on TEENSY 2.0++

    I have experience running LPD8806 code on an Arduino UNO.

    I am trying to run the same code on my TEENSY 2.0++ and its not working, yet.

    I know I need B1=clock and B2=data

    Where would I assign these within the code? Here is my current code for mapping between 2 colors on a strip with 80 LEDs:

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



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

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

    // Magenta:
    #define COLOR1_R 0
    #define COLOR1_G 0
    #define COLOR1_B 120
    // Blue:
    #define COLOR2_R 0
    #define COLOR2_G 120
    #define COLOR2_B 0


    LPD8806 strip = LPD8806(80, dataPin, clockPin);
    void setup() {
    // Start up the LED strip
    strip.begin();

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

    void loop()
    {
    int r,g,b;
    int rA, gA, bA, rB, gB, bB;

    uint16_t i, j, k, l, m;

    for (j=0; j < 140; j++) // fade over a range of 140 steps
    {
    // calculate pixels 0-39 color
    int rA = map(j, 0, 140, COLOR1_R, COLOR2_R);
    int gA = map(j, 0, 140, COLOR1_G, COLOR2_G);
    int bA = map(j, 0, 140, COLOR1_B, COLOR2_B);

    // calculate pixels 40-79 color
    int rB = map(j, 0, 140, COLOR2_R, COLOR1_R);
    int gB = map(j, 0, 140, COLOR2_G, COLOR1_G);
    int bB = map(j, 0, 140, COLOR2_B, COLOR1_B);

    for (i=0; i < 30; i++)
    {
    strip.setPixelColor(i,(strip.Color(rA,gA,bA) )); // set pixels 0-39
    strip.setPixelColor(i + 30,(strip.Color(rB,gB,bB) )); // set pixels 40-79
    }
    strip.show(); // write all pixels to the strip
    delay(1); // pause to appreciate...
    }

    for (j=0; j < 140; j++) // fade over a range of 140 steps
    {
    // calculate pixels 0-39 color
    int rA = map(j, 0, 140, COLOR2_R, COLOR1_R);
    int gA = map(j, 0, 140, COLOR2_G, COLOR1_G);
    int bA = map(j, 0, 140, COLOR2_B, COLOR1_B);

    // calculate pixels 40-79 color
    int rB = map(j, 0, 140, COLOR1_R, COLOR2_R);
    int gB = map(j, 0, 140, COLOR1_G, COLOR2_G);
    int bB = map(j, 0, 140, COLOR1_B, COLOR2_B);

    for (i=0; i < 30; i++)
    {
    strip.setPixelColor(i,(strip.Color(rA,gA,bA) )); // set pixels 0-39
    strip.setPixelColor(i + 30,(strip.Color(rB,gB,bB) )); // set pixels 40-79
    }
    strip.show(); // write all pixels to the strip
    delay(1); // pause to appreciate...
    }
    }

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,929
    Quote Originally Posted by slurry bowl View Post
    I know I need B1=clock and B2=data

    Where would I assign these within the code? Here is my current code for mapping between 2 colors on a strip with 80 LEDs:
    .......

    // Chose 2 pins for output; can be any valid output pins:
    int dataPin = 2;
    int clockPin = 1;
    I believe this should output the signals on pin 1 and 2, as labeled on the Arduino side of the pinout reference card that came with your Teensy++ 2.0 board (also available here).

    Those pins are labeled "D1" and "D2" on the C language side of the card, and on the printing on the board itself.

  3. #3
    ok. after consulting with some other folks on the web it seems I should expect B1 aka pin 21 and B2 aka pin 22 to be for clock and data respectively with the code below.

    I am still not getting any control of my LPD8806 strip. I am also not getting pin 11 to light up with BLINK sketch, but the pin is still working and will blink a standard LED.

    Anybody have any working code for LPD8806 and specific pins I could try? THANKS

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

    // Example to control LPD8806-based RGB LED Modules in a strip

    /************************************************** ***************************/

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

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

    // First parameter is the number of LEDs in the strand. The LED strips
    // are 32 LEDs per meter but you can extend or cut the strip. Next two
    // parameters are SPI data and clock pins:
    //LPD8806 strip = LPD8806(32, dataPin, clockPin);

    // You can optionally use hardware SPI for faster writes, just leave out
    // the data and clock pin parameters. But this does limit use to very
    // specific pins on the Arduino. For "classic" Arduinos (Uno, Duemilanove,
    // etc.), data = pin 11, clock = pin 13. For Arduino Mega, data = pin 51,
    // clock = pin 52. For 32u4 Breakout Board+ and Teensy, data = pin B2,
    // clock = pin B1. For Leonardo, this can ONLY be done on the ICSP pins.
    LPD8806 strip = LPD8806(nLEDs);

    void setup() {
    // Start up the LED strip
    strip.begin();

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


    void loop() {

    // Send a simple pixel chase in...
    colorChase(strip.Color(127, 127, 127), 50); // White
    colorChase(strip.Color(127, 0, 0), 50); // Red
    colorChase(strip.Color(127, 127, 0), 50); // Yellow
    colorChase(strip.Color( 0, 127, 0), 50); // Green
    colorChase(strip.Color( 0, 127, 127), 50); // Cyan
    colorChase(strip.Color( 0, 0, 127), 50); // Blue
    colorChase(strip.Color(127, 0, 127), 50); // Violet

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

    rainbow(10);
    rainbowCycle(0); // make it go through the cycle fairly fast
    }

    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));
    }

  4. #4
    Senior Member
    Join Date
    Jan 2013
    Posts
    120
    Relatedly - I just got a Teensy++2.0 last week and will hopefully getting the FastSPI_LED2 library up and running on it over the next few days. (I decided to step away from library dev/maintenance/packaging for a few days to work on a personal project - need to remind myself that I can also be a user of my library sometimes!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •