/* * Zapojení * VCC - Log1 , DIN - D02 , CS - D03 , CLK - D04 * */ int dataIn = 12; int load = 10; int clock = 11; unsigned int PacOpen[8]; unsigned int PacClosed[8]; int maxInUse = 4; //change this variable to set how many MAX7219's you'll use int e = 0; // just a variable // define max7219 registers byte max7219_reg_noop = 0x00; byte max7219_reg_digit0 = 0x01; byte max7219_reg_digit1 = 0x02; byte max7219_reg_digit2 = 0x03; byte max7219_reg_digit3 = 0x04; byte max7219_reg_digit4 = 0x05; byte max7219_reg_digit5 = 0x06; byte max7219_reg_digit6 = 0x07; byte max7219_reg_digit7 = 0x08; byte max7219_reg_decodeMode = 0x09; byte max7219_reg_intensity = 0x0a; byte max7219_reg_scanLimit = 0x0b; byte max7219_reg_shutdown = 0x0c; byte max7219_reg_displayTest = 0x0f; void putByte(byte data) { byte i = 8; byte mask; while(i > 0) { mask = 0x01 << (i - 1); // get bitmask digitalWrite( clock, LOW); // tick if (data & mask){ // choose bit digitalWrite(dataIn, HIGH);// send 1 }else{ digitalWrite(dataIn, LOW); // send 0 } digitalWrite(clock, HIGH); // tock --i; // move to lesser bit } } void maxSingle( byte reg, byte col) { //maxSingle is the "easy" function to use for a single max7219 digitalWrite(load, LOW); // begin putByte(reg); // specify register putByte(col);//((data & 0x01) * 256) + data >> 1); // put data digitalWrite(load, LOW); // and load da stuff digitalWrite(load,HIGH); } void zobraz ( byte x, byte y, bool col) { digitalWrite(load, LOW); // begin putByte(x); // specify register putByte(y);//((data & 0x01) * 256) + data >> 1); // put data digitalWrite(load, LOW); // and load da stuff digitalWrite(load,HIGH); } void maxAll (byte reg, byte col) { // initialize all MAX7219's in the system int c = 0; digitalWrite(load, LOW); // begin for ( c =1; c<= maxInUse; c++) { putByte(reg); // specify register putByte(col);//((data & 0x01) * 256) + data >> 1); // put data } digitalWrite(load, LOW); digitalWrite(load,HIGH); } void maxOne(byte maxNr, byte reg, byte col) { //maxOne is for addressing different MAX7219's, //while having a couple of them cascaded int c = 0; digitalWrite(load, LOW); // begin for ( c = maxInUse; c > maxNr; c--) { putByte(0); // means no operation putByte(0); // means no operation } putByte(reg); // specify register putByte(col);//((data & 0x01) * 256) + data >> 1); // put data for ( c =maxNr-1; c >= 1; c--) { putByte(0); // means no operation putByte(0); // means no operation } digitalWrite(load, LOW); // and load da stuff digitalWrite(load,HIGH); } void setup () { pinMode(dataIn, OUTPUT); pinMode(clock, OUTPUT); pinMode(load, OUTPUT); pinMode ( 5,INPUT); digitalWrite(13, HIGH); //initiation of the max 7219 maxAll(max7219_reg_scanLimit, 0x07); maxAll(max7219_reg_decodeMode, 0x00); // using an led matrix (not digits) maxAll(max7219_reg_shutdown, 0x01); // not in shutdown mode maxAll(max7219_reg_displayTest, 0x00); // no display test for (e=1; e<=8; e++) { // empty registers, turn all LEDs off maxAll(e,0); } maxAll(max7219_reg_intensity, 0x0f & 0x0f); // the first 0x0f is the value you can set // range: 0x00 to 0x0f PacOpen[0]=B00111100; PacOpen[1]=B01111110; PacOpen[2]=B11011100; PacOpen[3]=B11111000; PacOpen[4]=B11111000; PacOpen[5]=B11111000; PacOpen[6]=B01111110; PacOpen[7]=B00111100; PacClosed[0]=B00111100; PacClosed[1]=B01111110; PacClosed[2]=B11011111; PacClosed[3]=B11111111; PacClosed[4]=B11111000; PacClosed[5]=B11111111; PacClosed[6]=B01111110; PacClosed[7]=B00111100; } void loop () { int PacO[8], PacC[8]; //PC man for (int i=1;i<9;i++) { PacO[i-1]=PacOpen[i-1]*128; PacC[i-1]=PacClosed[i-1]*128; } for (int j=0;j<16;j++) { if (j<8) { // PacMan nedojel do pulky, zobrazime tecku (jidlo) PacO[4]+=4; PacC[4]+=4; } for (int i=1;i<9;i++) { maxSingle(i,PacO[i-1]); PacO[i-1]=PacO[i-1]/2; } if (j<8) {//Tecku musime vzdy soupnout zase zpet, jinak se bude posouvat s Pacmanem PacO[4]-=2; } /* do { if ( !digitalRead (5) ) break; } while (true);*/ delay (100); for (int i=1;i<9;i++) { maxSingle(i,PacC[i-1]); PacC[i-1]=PacC[i-1]/2; } if (j<8) {//Tecku musime vzdy soupnout zase zpet, jinak se bude posouvat s Pacmanem - v druhem obrazku PacC[4]-=2; } /* do { if ( !digitalRead (5)) break; } while (true);*/ delay (100); } }