How to connect two 2 digits 7 segment with Arduino using the MAX7219



7 Segment Display

A 7 segment display is basically just a couple of  regular LEDs behind a stencil. Each led lights up a particular segment


diagram 2 digit 7 Segment


MAX7219

MAX7219 is LED driver available it's probably the easiest to use and can control many LEDs using only one chip



schematic diagram

This schematic diagram  connect some capacitors to filter out the noise from the power supply,but this is optional ,You can built it without



Arduino Sketch

#include "LedControl.h"  // Library used for communcation with 7 segment

LedControl lc=LedControl(12,11,10,1);  //  (DIN, CLK, LOAD, number of Max7219 chips)

// Variable to hold current scores
int counter=0;

// Variables to split whole number into single digits
int digit1;
int digit2;
int digit3;
int digit4;

void setup() {
  
  lc.shutdown(0,false);  // Wake up MAX7219
  lc.setIntensity(0,2);  // Set brightness to medium
  lc.clearDisplay(0);  // Clear all displays connected to MAX7219 chip #
  

// Put zeros on both displays at startup
  
  lc.setDigit(0,0,0,false);  // (Max7219 chip #, Digit, value, DP on or off)
  lc.setDigit(0,1,0,false);

  lc.setDigit(0,2,0,false);  // (Max7219 chip #, Digit, value, DP on or off)
  lc.setDigit(0,3,0,false);
  
}


void loop() { 
  
  counter++;
  if( counter > 10000) counter = 0;

    digit1=counter%10;
    digit2=counter%100/10;
    digit3=counter%1000/100;
    digit4=counter%10000/1000;

    // Display extracted digits on the display
    lc.setDigit(0,0,digit1,true);
    lc.setDigit(0,1,digit2,false);

    lc.setDigit(0,2,digit3,false);
    lc.setDigit(0,3,digit4,false);

    delay(10);
  
}

ความคิดเห็น