mdraber
Published © LGPL

How to control 4 digit 7 segment display with MAX7219

Preparation to build my own custom 4 digit large segments display controlled with Max7219

IntermediateFull instructions provided6,714
How to control 4 digit 7 segment display with MAX7219

Things used in this project

Story

Read more

Schematics

Schematics

Code

Countin from 0 to 9999 using setDigit

Arduino
#include "LedControl.h"
LedControl lc=LedControl(12,11,10,1);
unsigned long delaytime=450;

void setup() {
  lc.shutdown(0,false);
  lc.setIntensity(0,8);
  lc.clearDisplay(0);
}

void loop() {  
  for(int i=0;i<9999;i++) {
    lc.setDigit(0,0,(int)i/1000,false);
    lc.setDigit(0,1,((int)i/100*100-(int)i/1000*1000)/100,false);
    lc.setDigit(0,2,((int)i/10*10-(int)i/100*100)/10,false);
    lc.setDigit(0,3,i-(int)i/10*10,false);
    delay(delaytime);
  }
}

Counting from 0 to 9999 using setRow command

Arduino
#include "LedControl.h"
LedControl lc=LedControl(12,11,10,1);
unsigned long delaytime=450;

int Digits[10]={B01111110, B00110000, B01101101, B01111001,
               B00110011, B01011011, B01011111, B01110000,
               B01111111, B01111011};
int dig1; int dig2; int dig3; int dig4;

void setup() {
  lc.shutdown(0,false);
  lc.setIntensity(0,8);
  lc.clearDisplay(0);
}

void loop() { 
  for(int i=0;i<9999;i++) {
    dig1=(int)i/1000;
    dig2=((int)i/100*100-(int)i/1000*1000)/100;
    dig3=((int)i/10*10-(int)i/100*100)/10;
    dig4= i-(int)i/10*10
    lc.setRow(0,0,Digits[dig1]);
    lc.setRow(0,1,Digits[dig2]);
    lc.setRow(0,2,Digits[dig3]);
    lc.setRow(0,3,Digits[dig4]);
    delay(delaytime);
  }
}

Displaying/Testing all segments of the display one by one

Arduino
#include "LedControl.h"
LedControl lc=LedControl(12,11,10,1);
unsigned long delaytime=450;

void setup() {
  lc.shutdown(0,false);
  lc.setIntensity(0,8);
  lc.clearDisplay(0);
}

void loop() {
for (int i=0;i<4;i++){
   int RowBits=B10000000; 
   for (int j=0;j<8;j++){
      lc.setRow(0,i, RowBits); 
      RowBits = RowBits >>1;
      delay(delaytime);
      lc.clearDisplay(0);
    }
  }
}

Credits

mdraber

mdraber

49 projects • 68 followers

Comments