Go Down

Topic: LED Controller with STP08DP05 (Read 594 times) previous topic - next topic

LinhartR

I had fun playing around with this LED controller. The chip was cheap enough and pretty easy to use. I ran out of room on my little breadboard or would have had an array of 24 single color LEDS. I did manage 16. As you can see from my YouTube video I did hook up 8 multicolor LEDs.

I encourage you to get some of these and try them out. If you found this fun or interesting please make a small donation to my PayPal account at https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=GTBD7T7BXPGQY. I have many more Arduino projects in mind and appreciate your support.

See my YouTube video at http://youtu.be/x20uNWz1Res.

Code: [Select]

/* LED Driver for STP08DP05
* ------------------------
*
* Demo shows bitmap on 8 x multi color LEDs
*
*/

// Debug message flag. Comment line below to disable Serial debug messages.
// #define _DEBUG

// Serial data input terminal pin 2. ORN.
const byte _SDI_RED = 8;
const byte _SDI_GRN = 7;
const byte _SDI_BLU = 6;
// Latch input terminal pin 4. DM1. YEL.
const byte _LE = 9;
// Clock input terminal pin 3. BLK.
const byte _CLK = 10;
// Output enable input terminal pin 13 (active low). DM2. WHT.
const byte _OE = 11;
// Number of LEDs. Used when chaining devices.
const byte LEDCntMax = 8;
// LED brightness delay in millis().
unsigned long brightDly = 40;
// Init bitmap.
const byte bmNumIndexMax = 5;
const byte bmIndexMaxSize = 56;
const byte bmNumColors = 3;
const byte bmIndexRed = 0;
const byte bmIndexGrn = 1;
const byte bmIndexBlu = 2;
const byte bm[bmNumIndexMax][bmIndexMaxSize+1][bmNumColors] = {
  {
    {14, 50, 0},
    {0x01, 0x00, 0x00}, {0x00, 0x02, 0x00}, {0x00, 0x00, 0x04},
    {0x08, 0x00, 0x00}, {0x00, 0x10, 0x00}, {0x00, 0x00, 0x20},
    {0x40, 0x00, 0x00}, {0x00, 0x80, 0x00}, {0x40, 0x00, 0x00},
    {0x00, 0x00, 0x20}, {0x00, 0x10, 0x00}, {0x08, 0x00, 0x00},
    {0x00, 0x00, 0x04}, {0x00, 0x02, 0x00}
  },
  {
    {3, 150, 0},
    {0x49, 0x92, 0x24}, {0x92, 0x24, 0x49}, {0x24, 0x49, 0x92}
  },
  {
    {56, 25, 0},
    {0x01, 0x01, 0x01}, {0x02, 0x02, 0x02}, {0x04, 0x04, 0x04},
    {0x08, 0x08, 0x08}, {0x10, 0x10, 0x10}, {0x20, 0x20, 0x20},
    {0x40, 0x40, 0x40}, {0x80, 0x80, 0x80}, {0x40, 0x40, 0x40},
    {0x20, 0x20, 0x20}, {0x10, 0x10, 0x10}, {0x08, 0x08, 0x08},
    {0x04, 0x04, 0x04}, {0x02, 0x02, 0x02},
    {0x01, 0x00, 0x00}, {0x02, 0x00, 0x00}, {0x04, 0x00, 0x00},
    {0x08, 0x00, 0x00}, {0x10, 0x00, 0x00}, {0x20, 0x00, 0x00},
    {0x40, 0x00, 0x00}, {0x80, 0x00, 0x00}, {0x40, 0x00, 0x00},
    {0x20, 0x00, 0x00}, {0x10, 0x00, 0x00}, {0x08, 0x00, 0x00},
    {0x04, 0x00, 0x00}, {0x02, 0x00, 0x00},
    {0x00, 0x01, 0x00}, {0x00, 0x02, 0x00}, {0x00, 0x04, 0x00},
    {0x00, 0x08, 0x00}, {0x00, 0x10, 0x00}, {0x00, 0x20, 0x00},
    {0x00, 0x40, 0x00}, {0x00, 0x80, 0x00}, {0x00, 0x40, 0x00},
    {0x00, 0x20, 0x00}, {0x00, 0x10, 0x00}, {0x00, 0x08, 0x00},
    {0x00, 0x04, 0x00}, {0x00, 0x02, 0x00},
    {0x00, 0x00, 0x01}, {0x00, 0x00, 0x02}, {0x00, 0x00, 0x04},
    {0x00, 0x00, 0x08}, {0x00, 0x00, 0x10}, {0x00, 0x00, 0x20},
    {0x00, 0x00, 0x40}, {0x00, 0x00, 0x80}, {0x00, 0x00, 0x40},
    {0x00, 0x00, 0x20}, {0x00, 0x00, 0x10}, {0x00, 0x00, 0x08},
    {0x00, 0x00, 0x04}, {0x00, 0x00, 0x02}
  },
  {
    {6,200,0},
    {0x35, 0x2e, 0x81}, {0x76, 0x3e, 0x82}, {0xf6, 0x3f, 0xa2},
    {0x59, 0xff, 0xa3}, {0x79, 0xe7, 0xa7}, {0x39, 0xe3, 0xa3}
  },
  {
    {15,60,0},
    {0x00, 0x01, 0x00}, {0x00, 0x03, 0x00}, {0x00, 0x07, 0x00},
    {0x00, 0x0f, 0x00}, {0x10, 0x1f, 0x00}, {0x30, 0x3f, 0x00},
    {0x70, 0x3f, 0x00}, {0xf0, 0x3f, 0x00}, {0x70, 0x3f, 0x00},
    {0x30, 0x3f, 0x00}, {0x10, 0x1f, 0x00}, {0x00, 0x0f, 0x00},
    {0x00, 0x07, 0x00}, {0x00, 0x03, 0x00}, {0x00, 0x02, 0x00}
  }
};
byte bmNumIndex = 0;
byte bmIndexMax = bm[bmNumIndex][0][0];
byte bmBrightDly = bm[bmNumIndex][0][1];
// Button.
const byte _BTN = 2;
boolean btnLast = false;

// setup() runs once after reset.
void setup()
{
  #if defined _DEBUG
  Serial.begin(9600);
  Serial.println("setup() begin!");
  #endif
  // Init LED driver terminals.
  pinMode(_SDI_RED, OUTPUT);
  pinMode(_SDI_GRN, OUTPUT);
  pinMode(_SDI_BLU , OUTPUT);
  digitalWrite(_CLK, LOW);
  pinMode(_CLK, OUTPUT);
  digitalWrite(_LE, HIGH);
  pinMode(_LE, OUTPUT);
  digitalWrite(_OE, LOW);
  pinMode(_OE, OUTPUT);
  // Init button.
  pinMode(_BTN, INPUT_PULLUP);
  #if defined _DEBUG
  Serial.println("setup() end!");
  #endif
}

// loop() runs continuously after setup().
void loop() {
  #if defined _DEBUG
  Serial.println("loop() begin!");
  Serial.println("bmNumIndex=" + String(bmNumIndex) + ".");
  Serial.println("bmIndexMax=" + String(bmIndexMax) + ".");
  Serial.println("bmBrightDly=" + String(bmBrightDly) + ".");
  #endif
  // Output bitmap to LEDs.
  for (int bmIndex = 1; bmIndex <= bmIndexMax; bmIndex++) {
    // Set latch input LOW.
    digitalWrite(_LE, LOW);
    #if defined _DEBUG
    Serial.println("Set LE LOW!");
    #endif
    // Set output enable input HIGH (active low).
    // digitalWrite(_OE, HIGH);
    #if defined _DEBUG
    // Serial.println("Set OE HIGH!");
    #endif
    // Shift bits out to LED driver.
    int dataOutRed = bm[bmNumIndex][bmIndex][bmIndexRed];
    int dataOutGrn = bm[bmNumIndex][bmIndex][bmIndexGrn];
    int dataOutBlu = bm[bmNumIndex][bmIndex][bmIndexBlu];
    #if defined _DEBUG
    //dataOut = 05;
    Serial.println("dataOutRed=" + String(dataOutRed) + ".");
    Serial.println("dataOutGrn=" + String(dataOutGrn) + ".");
    Serial.println("dataOutBlu=" + String(dataOutBlu) + ".");
    #endif   
    for (byte count = 1; count <= LEDCntMax; count++) {
      // Update data input.
      digitalWrite(_SDI_RED, dataOutRed & 01);
      digitalWrite(_SDI_GRN, dataOutGrn & 01);
      digitalWrite(_SDI_BLU, dataOutBlu & 01);
      #if defined _DEBUG
      // Serial.println("SDI=" + String(dataOut & 01) + ".");
      #endif
      // Cycle clock.
      #if defined _DEBUG
      //Serial.println("Cycle Clock begin!");
      #endif
      // Clock high.
      digitalWrite(_CLK, HIGH);
      // Clock low.
      digitalWrite(_CLK, LOW);
      #if defined _DEBUG
      // Slow down clock for _DEBUG.
      // delay(500);
      // Serial.println("Cycle Clock end!");
      #endif
      // Shift in next bit.
      dataOutRed >>= 1;
      dataOutGrn >>= 1;
      dataOutBlu >>= 1;
      // Update btn status.
      btnLast |= !digitalRead(_BTN);
      #if defined _DEBUG
      if (btnLast) {
        Serial.println("Button pressed detected!");
      }
      #endif
    }
    // Set latch input HIGH.
    digitalWrite(_LE, HIGH);
    #if defined _DEBUG
    // Serial.println("Set LE HIGH!");
    #endif
    // Set output enable input LOW (active low).
    // digitalWrite(_OE, LOW);
    #if defined _DEBUG
    // Serial.println("Set OE LOW!");
    #endif
    // LED brightness delay.
    delay(bmBrightDly);
  }
  // Button pressed?
  if (btnLast) {
    #if defined _DEBUG
    Serial.println("Button pressed!");
    #endif
    // Yes, Clear button pressed.
    btnLast = false;
    // Incremented bitmap index > max?
    bmNumIndex++;
    if (bmNumIndex >= bmNumIndexMax) {
      // Yes, Reset bitmap index.
      bmNumIndex = 0;
    }
    bmIndexMax = bm[bmNumIndex][0][0];
    bmBrightDly = bm[bmNumIndex][0][1];
    #if defined _DEBUG
    Serial.println("bmNumIndex" + String(bmNumIndex) + ".");
    Serial.println("bmIndexMax" + String(bmIndexMax) + ".");
    #endif
    // Debounce button
    delay(500);
  }
  #if defined _DEBUG
  Serial.println("loop() end!");
  #endif
}

Go Up