#define CLK 13
#define DIN 11
#define CS 10
#define X_SEGMENTS 4 //??????
#define Y_SEGMENTS 2
#define NUM_SEGMENTS (X_SEGMENTS * Y_SEGMENTS)
// a framebuffer to hold the state of the entire matrix of LEDs
// laid out in raster order, with (0, 0) at the top-left
byte fb[8 * NUM_SEGMENTS];
void shiftAll(byte send_to_address, byte send_this_data)
{
//start communication
digitalWrite(CS, LOW);
for (int i = 0; i < NUM_SEGMENTS; i++) {
//send an address and the data
shiftOut(DIN, CLK, MSBFIRST, send_to_address);
shiftOut(DIN, CLK, MSBFIRST, send_this_data);
}
digitalWrite(CS, HIGH);
}
void setup() {
Serial.begin(115200);
pinMode(CLK, OUTPUT);
pinMode(DIN, OUTPUT);
pinMode(CS, OUTPUT);
// Setup each MAX7219
shiftAll(0x0f, 0x00); //display test register - test mode off
shiftAll(0x0b, 0x07); //scan limit register - display digits 0 thru 7
shiftAll(0x0c, 0x01); //shutdown register - normal operation
shiftAll(0x0a, 0x0f); //intensity register - max brightness
shiftAll(0x09, 0x00); //decode mode register - No decode
}
void show() {
for (byte row = 0; row < 8; row++) {
digitalWrite(CS, LOW);
byte segment = NUM_SEGMENTS;
while (segment--) {
//compute row and column
byte x = segment % X_SEGMENTS;
byte y = segment / X_SEGMENTS * 8;
//compute address given the above
byte addr = (row + y) * X_SEGMENTS;
// odd rows of segments
if (segment & X_SEGMENTS) {
shiftOut(DIN, CLK, MSBFIRST, 8 - row); //?????
shiftOut(DIN, CLK, LSBFIRST, fb[addr + x]);
} else {
shiftOut(DIN, CLK, MSBFIRST, 1 + row);
shiftOut(DIN, CLK, MSBFIRST, fb[addr - x + X_SEGMENTS - 1]);
}
}
digitalWrite(CS, HIGH);
}
}
void loop(){
for(int i=0; i<64; i++) fb[i]=0;
// fb[(millis()/1000)%64] = (1<<(millis()/125%8)); // inlocuiti asta cu fb[0]=B00000011; fb[63] = 255;
fb[0]=B00000011;
fb[63] = B00000001;
show();
}