/*This software is provided in an “AS IS” condition,NO WARRANTIES in any form apply to this software. picmicrolab.com 11.04.2017 *************************************************************************************************************** //8x8 LED Dot Matrix Display with Arduino */ //***********MAX7219 pins************************** //2- Data Out //3- CLK //4 -Load int DataOUT = 2; int CLK = 3; int Load = 4; void setup() { // initialize I/O pins. pinMode(DataOUT, OUTPUT); // pinMode(CLK, OUTPUT); // pinMode(Load, OUTPUT); // digitalWrite(Load,HIGH); digitalWrite(CLK,HIGH); digitalWrite(Load,HIGH); //delay(500); //***************************MAX7219 Init***************************************** SendDataMax7219(0xfc,0xff);//Normal Operation //delay(500); SendDataMax7219(0xfa,0xf1);//Intensity //delay(500); //SendDataMax7219(0xff,0xff);//Display Test SendDataMax7219(0xfB,0xf7); //Scan-Limit Register Format Digits 0,1,2,3 are ON //delay(500); SendDataMax7219(0xf9,0x00);//Decode Mode - Code B Font delay(500); //******************************************************************************** } void loop() { for(int i =0;i<16;i++) { SendDataDotMatrix(i); delay(1000); } } void SendDataDotMatrix(int Digit) { if(Digit == 1) { //-----------------Show 1---------------------- SendDataMax7219(0xf1,0x10); SendDataMax7219(0xf2,0x30); SendDataMax7219(0xf3,0x10); SendDataMax7219(0xf4,0x10); SendDataMax7219(0xf5,0x10); SendDataMax7219(0xf6,0x10); SendDataMax7219(0xf7,0x10); SendDataMax7219(0xf8,0x00); //--------------------------------------------- } if(Digit == 2) { //-----------------Show 2---------------------- SendDataMax7219(0xf1,0x7c); SendDataMax7219(0xf2,0x04); SendDataMax7219(0xf3,0x04); SendDataMax7219(0xf4,0x7c); SendDataMax7219(0xf5,0x40); SendDataMax7219(0xf6,0x40); SendDataMax7219(0xf7,0x7c); SendDataMax7219(0xf8,0x00); } //--------------------------------------------- if(Digit == 3) { //-----------------Show 3---------------------- SendDataMax7219(0xf1,0x7c); SendDataMax7219(0xf2,0x04); SendDataMax7219(0xf3,0x04); SendDataMax7219(0xf4,0x3c); SendDataMax7219(0xf5,0x04); SendDataMax7219(0xf6,0x04); SendDataMax7219(0xf7,0x7c); SendDataMax7219(0xf8,0x00); } //--------------------------------------------- if(Digit == 4) { //-----------------Show 4---------------------- SendDataMax7219(0xf1,0x44); SendDataMax7219(0xf2,0x44); SendDataMax7219(0xf3,0x44); SendDataMax7219(0xf4,0x7c); SendDataMax7219(0xf5,0x04); SendDataMax7219(0xf6,0x04); SendDataMax7219(0xf7,0x04); SendDataMax7219(0xf8,0x00); } //--------------------------------------------- if(Digit == 5) { //-----------------Show 5---------------------- SendDataMax7219(0xf1,0x7c); SendDataMax7219(0xf2,0x40); SendDataMax7219(0xf3,0x40); SendDataMax7219(0xf4,0x7c); SendDataMax7219(0xf5,0x04); SendDataMax7219(0xf6,0x04); SendDataMax7219(0xf7,0x7c); SendDataMax7219(0xf8,0x00); } //--------------------------------------------- if(Digit == 6) { //-----------------Show 6---------------------- SendDataMax7219(0xf1,0x7c); SendDataMax7219(0xf2,0x40); SendDataMax7219(0xf3,0x40); SendDataMax7219(0xf4,0x7c); SendDataMax7219(0xf5,0x44); SendDataMax7219(0xf6,0x44); SendDataMax7219(0xf7,0x7c); SendDataMax7219(0xf8,0x00); } //--------------------------------------------- if(Digit == 7) { //-----------------Show 7---------------------- SendDataMax7219(0xf1,0x7c); SendDataMax7219(0xf2,0x04); SendDataMax7219(0xf3,0x04); SendDataMax7219(0xf4,0x08); SendDataMax7219(0xf5,0x10); SendDataMax7219(0xf6,0x10); SendDataMax7219(0xf7,0x10); SendDataMax7219(0xf8,0x00); } //--------------------------------------------- if(Digit == 8) { //-----------------Show 8---------------------- SendDataMax7219(0xf1,0x7c); SendDataMax7219(0xf2,0x44); SendDataMax7219(0xf3,0x44); SendDataMax7219(0xf4,0x7c); SendDataMax7219(0xf5,0x44); SendDataMax7219(0xf6,0x44); SendDataMax7219(0xf7,0x7c); SendDataMax7219(0xf8,0x00); } //--------------------------------------------- if(Digit == 9) { //-----------------Show 9---------------------- SendDataMax7219(0xf1,0x7c); SendDataMax7219(0xf2,0x44); SendDataMax7219(0xf3,0x44); SendDataMax7219(0xf4,0x7c); SendDataMax7219(0xf5,0x04); SendDataMax7219(0xf6,0x04); SendDataMax7219(0xf7,0x7c); SendDataMax7219(0xf8,0x00); } //--------------------------------------------- if(Digit == 0) { //-----------------Show 0---------------------- SendDataMax7219(0xf1,0x7c); SendDataMax7219(0xf2,0x44); SendDataMax7219(0xf3,0x44); SendDataMax7219(0xf4,0x44); SendDataMax7219(0xf5,0x44); SendDataMax7219(0xf6,0x44); SendDataMax7219(0xf7,0x7c); SendDataMax7219(0xf8,0x00); } //--------------------------------------------- if(Digit == 10) { //-----------------Show A---------------------- SendDataMax7219(0xf1,0x38); SendDataMax7219(0xf2,0x44); SendDataMax7219(0xf3,0x44); SendDataMax7219(0xf4,0x7C); SendDataMax7219(0xf5,0x44); SendDataMax7219(0xf6,0x44); SendDataMax7219(0xf7,0x44); SendDataMax7219(0xf8,0x00); } //--------------------------------------------- if(Digit == 11) { //-----------------Show B---------------------- SendDataMax7219(0xf1,0x78); SendDataMax7219(0xf2,0x44); SendDataMax7219(0xf3,0x44); SendDataMax7219(0xf4,0x78); SendDataMax7219(0xf5,0x44); SendDataMax7219(0xf6,0x44); SendDataMax7219(0xf7,0x78); SendDataMax7219(0xf8,0x00); } //--------------------------------------------- if(Digit == 12) { //-----------------Show C---------------------- SendDataMax7219(0xf1,0x38); SendDataMax7219(0xf2,0x44); SendDataMax7219(0xf3,0x40); SendDataMax7219(0xf4,0x40); SendDataMax7219(0xf5,0x40); SendDataMax7219(0xf6,0x44); SendDataMax7219(0xf7,0x38); SendDataMax7219(0xf8,0x00); } //--------------------------------------------- if(Digit == 13) { //-----------------Show D---------------------- SendDataMax7219(0xf1,0x78); SendDataMax7219(0xf2,0x44); SendDataMax7219(0xf3,0x44); SendDataMax7219(0xf4,0x44); SendDataMax7219(0xf5,0x44); SendDataMax7219(0xf6,0x44); SendDataMax7219(0xf7,0x78); SendDataMax7219(0xf8,0x00); } //--------------------------------------------- if(Digit == 14) { //-----------------Show E---------------------- SendDataMax7219(0xf1,0x7C); SendDataMax7219(0xf2,0x40); SendDataMax7219(0xf3,0x40); SendDataMax7219(0xf4,0x78); SendDataMax7219(0xf5,0x40); SendDataMax7219(0xf6,0x40); SendDataMax7219(0xf7,0x7C); SendDataMax7219(0xf8,0x00); } //--------------------------------------------- if(Digit == 15) { //-----------------Show F---------------------- SendDataMax7219(0xf1,0x7C); SendDataMax7219(0xf2,0x40); SendDataMax7219(0xf3,0x40); SendDataMax7219(0xf4,0x78); SendDataMax7219(0xf5,0x40); SendDataMax7219(0xf6,0x40); SendDataMax7219(0xf7,0x40); SendDataMax7219(0xf8,0x00); } } void SendDataMax7219(int HighByte,int LowByte) { //---------------Send High Byte-------------- for(int i=7;i>-1;i--) { if(bitRead(HighByte, i)== HIGH) { digitalWrite(DataOUT,HIGH); //delay(1); digitalWrite(CLK,LOW); //delay(1); digitalWrite(CLK,HIGH); //delay(1); digitalWrite(CLK,LOW); } if(bitRead(HighByte, i)== LOW) { digitalWrite(DataOUT,LOW); //delay(1); digitalWrite(CLK,LOW); //delay(1); digitalWrite(CLK,HIGH); //delay(1); digitalWrite(CLK,LOW); } } //------------------------------------------ //---------------Send Low Byte-------------- for(int i=7;i>-1;i--) { if(bitRead(LowByte, i)== HIGH) { digitalWrite(DataOUT,HIGH); //delay(1); digitalWrite(CLK,LOW); //delay(1); digitalWrite(CLK,HIGH); //delay(1); digitalWrite(CLK,LOW); } if(bitRead(LowByte, i)== LOW) { digitalWrite(DataOUT,LOW); //delay(1); digitalWrite(CLK,LOW); //delay(1); digitalWrite(CLK,HIGH); //delay(1); digitalWrite(CLK,LOW); } } //---------------------------------------- //--------Load 16 bit number in MAX7219--- //delay(1); digitalWrite(Load,LOW); //delay(1); digitalWrite(Load,HIGH); //delay(1); digitalWrite(Load,LOW); //---------------------------------------- }