//We always have to include the library for control LED
#include "LedControl.h"
/*
Now we need a LedControl to work with.
***** These pin numbers will probably not work with your hardware *****
pin 4 is connected to the DataIn
pin 5 is connected to the CLK
pin 10 is connected to LOAD
We have only a single MAX72XX.
*/
// LedControl lc=LedControl(12,11,10,1);
#define CLK_11 5 // Connect CLK to Arduino port 5
#define DATA_IN_12 4 // Connect DIN/DATA IN to Arduino Port 4
#define LOAD_10 10 // Connect CS to Arduino Port 10
/* Declare variable for Led Control */
LedControl lc=LedControl(DATA_IN_12,CLK_11,LOAD_10,1);
/* we always wait a bit between updates of the display */
unsigned long delaytime=3000;
void setup() {
/*
The MAX72XX is in power-saving mode on startup,
we have to do a wakeup call
*/
lc.shutdown(0,false);
/* Set the brightness to a medium values */
lc.setIntensity(0,8);
/* and clear the display */
lc.clearDisplay(0);
}
void loop() {
/* Variable declaration */
/* new_0 is array to contain Truth table frpom 0 to 9 */
byte new_0[][5]=
{
{B00000111,B00000101,B00000101,B00000101,B00000111}, //0
{B00000001,B00000001,B00000001,B00000001,B00000001}, //1
{B00000111,B00000100,B00000111,B00000001,B00000111}, //2
{B00000111,B00000100,B00000111,B00000100,B00000111}, //3
{B00000101,B00000101,B00000111,B00000100,B00000100}, //4
{B00000111,B00000001,B00000111,B00000100,B00000111}, //5
{B00000111,B00000001,B00000111,B00000101,B00000111}, //6
{B00001111,B00001000,B00001000,B00001000,B00001000}, //7
{B00001111,B00001001,B00001111,B00001001,B00001111}, //8
{B00001111,B00001001,B00001111,B00001000,B00001111} //9
};
// Loop 10 times to display 0-9 to 8x8 dot matrix
for(int i=0;i<10;i++) {
// iterate for digit from i=0 (digit '0') to 9 ( digit '9')
for(int j=0;j<5;j++) {
// Display each dot in a row,from Row 0 to 4
lc.setRow(0,j,new_0[i][j]);
}
// Wait 3 seconds
delay(delaytime);
}
// Display 1o digits from 0 to 9 randomizely
for(int i=0;i<10;i++) {
// iterate 10 times
// Generate a random integer from 0 to 9
int k=random(0,9);
for(int j=0;j<5;j++) {
// Display the random number
lc.setRow(0,j,new_0[k][j]);
}
// Wait 3 seconds
delay(delaytime);
}
}