MAX7219 with LedControl: Two Colours


I'm using the MAX 7219 with the LedControl Library. I'm using two ICs, one to control 8 seven segments and the second to control an 8x8 LED matrix. I'm using this arrangement to display a tachometer signal.
I know it's not recommended to use an Led matrix with more than one colour on it, but I went ahead and tried anyway.
The majority of the LEDs are white in the matrix, there are a total of 7 blue LEDs.
Now when I test the matrix (to check if the wiring is fine) by lighting up each LED one by one and leaving them on, the matrix works fine.
However when I upload the program containing the Tacho signal processing and processing for another potentiometer, three blue LEDs flicker.

If I output only these three LEDs then they don't flicker, however with the whole program there is flickering which I haven't been able to eliminate or understand.

Does the fact that all the LEDs of the LED matrix are lit all at once mean that there is no current/wiring problem?

I haven't been able to figure out if there is something in program that's causing it to flicker, so I'm pasting my code here.

Before I change the blue LEDs I just want to make sure that they are the problem.

#include "LedControl.h"

int pot=0;
unsigned long time;
volatile int count=0;
LedControl lc=LedControl(12,11,10,2);
//pin 12 is connected to the DataIn 
// pin 11 is connected to the CLK 
// pin 10 is connected to LOAD 
unsigned long delaytime=100;

void setup() {
void rpm_count()

void rpm_display()
    //Calculating rpm
    float no_of_revs=count;
    float rpm=no_of_revs*4*60;
    //Getting separate digits to display on Seven Segment
    int rpm_digit4=(rpm/10000);
    int rpm_digit3=(rpm/1000)-(rpm_digit4*10);
    int rpm_digit2=(rpm/100)-(rpm_digit3*10)-(rpm_digit4*100);
    int rpm_digit1=(rpm/10)-(rpm_digit2*10)-(rpm_digit3*100)-(rpm_digit4*1000);
    int rpmint=rpm;
    int rpm_digit0=rpmint%10;
    //Setting the digits
    //Setting the led column
    float rpm_led=rpm-2000.0;
    int rpm_led_int=rpm_led;
    for(int i=6;i>=rpm_led_int;i--)
    for(int j=rpm_led_int-1;j>=0;j--)

void pot_display()
    float pot_float=pot/1024.0;
    int pot_int=pot_float;
    for(int i=6;i>=pot_int;i--)
    for(int j=pot_int-1;j>=0;j--)

  void loop()
    unsigned long x=millis();
    unsigned long y=x-time;
    //The problem is in these Leds:

Any theories?


First off please use the # icon when posting code not the quote icon as the # gives a nice scrolling box. Please modify your first post.

The MAX7219 multiplexes the LEDs in hardware so there is little you can do in the software to make them flash if you are not constantly accessing the chip. Therefore I suspect it is how you have wired them up that is the problem. Can you post a schematic?

Sorry about that. I just right clicked on the Wiring UI and clicked on copy for forum.

I'm attaching the schematic. I've attached two images, one with the whole schematic which I'm not sure is very clear and one with just the second IC and the connections.

I asked whether it was a programming problem because of the fact that the blue LEDs do not flicker when I just light up the whole matrix, only when I use this code.