0

I've been struggling for a long time trying to get the MM5451 chip to light up all 35 leds sequentially without any luck. I've had intermittent help from the arduino forum, someone on youtube, and even found source code on here. But all I've been able to accomplish is either to get all the lights lit up at once, or every other led lit up at once, or having two sets of 8 leds lighting up sequentially together. I can't figure out how to get all of them lit on and off sequentially. I'm sure it has to do with shifting bits but can't figure out how to do this. Here's two sets of code that either light two sets of 8 bits together sequentially, and another program that lights every other led all at once.

Sequential lighting of two sets of 8 bits

#define CLK 2 // to MM5451 pin 21
#define dataBit  3 // to MM5451 pin 22


 byte singleled[]=  {1,2,4,8,16,32,64,128};
//   0b00000001, 0b00000010, 0b00000100,
 //  0b00001000, 0b00010000, 0b00100000,
 //  0b01000000, 0b10000000, 0b11111111 };

  byte singleled2[]=  {1,2,4,8,16,32,64,128};
 //  0b00000001, 0b00000010, 0b00000100,
 //  0b00001000, 0b00010000, 0b00100000,
 //  0b01000000, 0b10000000, 0b11111111 };


void setup() {
  pinMode(CLK, OUTPUT);
  pinMode(dataBit, OUTPUT);
  digitalWrite(CLK, 0);
  digitalWrite(dataBit, 0); 
  Serial.begin(1200);
}

// the loop routine runs over and over again forever:
void loop() {


  for (int i=0; i<8; i++)   {
        // start bit
    digitalWrite(dataBit, 1);
    pulseCLK();
    // the "+ 0x80" turns on DP
    ssrWriteLSB(singleled2 [i]); // MOD myCount = 0-9  
    ssrWriteMSB (singleled [i]); // eight LEDs binary count 0-255
      delay(500);
   // ssrWriteMSB(myCount);
    //Serial.println(myCount);
    delay(500);
   // Serial.println(myCount);
    zeroWrite(29); // pad remaining bits with 0s
    delay(500);
  }


} // end loop


void pulseCLK()   {
  digitalWrite(CLK, 1);
  digitalWrite(CLK, 0);
}


// LSB out first!
void ssrWriteLSB(byte value)   {
  Serial.println(value);
  for(int x =0; x < 8; x++)   {
    byte temp = value & 0x01;
    if (temp == 0x01)   digitalWrite(dataBit, 1); // data bit HIGH
    else digitalWrite(dataBit, 0); // data bit LOW
    pulseCLK();
   value = value >> 0x01; // shift right
  }
}

// MSB out first!
void ssrWriteMSB(byte value)   {
 Serial.println(value);
  for(int x =0; x < 8; x++)   {
    byte temp = value & 0x80;
    if (temp == 0x80)   digitalWrite(dataBit, 1); // data bit HIGH
    else digitalWrite(dataBit, 0); // data bit LOW
    pulseCLK();
    value = value << 0x01; // shift left
  }
}

void  zeroWrite(byte num1)   {
  digitalWrite(dataBit, 0); // data bit LOW
  for(int x = 0; x < num1; x++) pulseCLK();
}

Turns on every other light all at once:

#define dataBit 3
#define clk 2


void setup()  {
  Serial.begin(1200);
  pinMode(dataBit, OUTPUT);
  pinMode(clk, OUTPUT);
  digitalWrite(dataBit, 0);
  digitalWrite(clk, 0);
}

 void loop() {
     //digitalWrite(dataBit,1);     
     for(int index=0; index < 36; index++)  {
          digitalWrite(dataBit,1);
          digitalWrite(clk,1);
          digitalWrite(clk,0); 
          digitalWrite(dataBit,0);
          digitalWrite(clk,1);
          digitalWrite(clk,0);
      }
  }

Thanks in advance.

Bryan

1 Answer 1

1

I think you need something like this.

#define CLK 2 // to MM5451 pin 21
#define DATA  3 // to MM5451 pin 22

void setup() 
{
    pinMode(CLK, OUTPUT);
    pinMode(DATA, OUTPUT);
    digitalWrite(CLK, 0);
    digitalWrite(DATA, 0); 
    Serial.begin(1200);
}

// the loop routine runs over and over again forever:
void loop() 
{
    for( byte led=0; led<35; led++ )
    {

        lightLed(led);


        delay(1000);    
    }
}

void lightLed(byte index)
{
    //always send a one first
    sendOne();
    // turn off all leds preceding index
    for( byte i=0; i<index; i++ )
        sendZero();
    // one led on
    sendOne();
    // pad with leds off
    for( byte i=index+1; i<35; i++ )
        sendZero();
}

void sendOne()
{
    digitalWrite(DATA, HIGH);
    digitalWrite(CLK, HIGH);
    digitalWrite(CLK, LOW);
}
void sendZero()
{
    digitalWrite(DATA, LOW);
    digitalWrite(CLK, HIGH);
    digitalWrite(CLK, LOW);
}
1
  • 1
    Gerben You're a genius!!! Thank you soooo much! This works beautifully! I knew it needed two loops and two separate routines but all i had as a reference was an 8 bit count and just couldn't figure out how to implement it with a 36 bit count. Once again I can't thank you enough! Really appreciate it!!! Best regards, Bryan
    – user8498
    Commented Apr 15, 2015 at 19:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.