Bilgiler > Arduino Max7219 Clock Sample
Arduino Max7219 Clock Sample
#define MAX7219_DIN 10
#define MAX7219_CS 9
#define MAX7219_CLK 12
int max9 = 9;
int max6 = 5;
int max4 = 4;
int max2 = 2;
int s5 = 0;
int s9 = 0;
int m5 = 0;
int m9 = 0;
int h2 = 0;
int h4 = 0;
void initialise()
{
digitalWrite(MAX7219_CS, HIGH);
pinMode(MAX7219_DIN, OUTPUT);
pinMode(MAX7219_CS, OUTPUT);
pinMode(MAX7219_CLK, OUTPUT);
}
void output(byte address, byte data)
{
digitalWrite(MAX7219_CS, LOW);
shiftOut(MAX7219_DIN, MAX7219_CLK, MSBFIRST, address);
shiftOut(MAX7219_DIN, MAX7219_CLK, MSBFIRST, data);
digitalWrite(MAX7219_CS, HIGH);
}
void setup() {
// put your setup code here, to run once:
output(0x0c, 0x01); //shutdown register - normal operation
output(0x0b, 0x07); //scan limit register - display digits 0 thru 7
output(0x0a, 0x0f); //intensity register - max brightness
output(0x09, 0xff); //decode mode register - CodeB decode all digits
}
void loop() {
// put your main code here, to run repeatedly:
if (s9 < max9) { s9++; }
else {s9 = 0; s5++;}
if (s5 > max6){s5 = 0;}
//if (s5 = 0){m9++;}
/*if (m9 = max9){m9 = 0;}
if (m9=0){m5++;}
if (m5 = max6){m5 = 0;}
if (m5=0){h4++;}
if (h4 = max4){h4 = 0;}
if (h4=0){h2++;}
if ((h2 = 2) && (h4 = 4) && (m5 = 5) && (m9= 9) && (s5= 5) && (s9= 9)) {h2 = 0; h4 = 0; m5 = 0; m9= 0; s5= 0; s9= 0;}*/
initialise();
output(0x0f, 0x00); //display test register - test mode off
output(0x0a, 0x0f); //intensity register - max brightness
output(0x09, 0xff); //decode mode register - CodeB decode all digits
output(0x06, h2);
output(0x05, h4);
output(0x04, m5);
output(0x03, m9);
output(0x02, s5);
output(0x01, s9); //digit 0 (rightmost digit) data
delay (1);
}
***