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