/* General notes: -if you are only using one max7219, then use the function maxSingle to control the little guy --- maxSingle(register (1-8), collum (0-255)) -if you are using more then one max7219, and they all should work the same, then use the function --- maxAll ---maxAll(register (1-8), collum (0-255)) -if you are using more than one max7219 and just want to change some thing at one little guy, then use the function maxOne --- maxOne(Max you wane controll (1== the first one), register (1-8), collum (0-255)) /* During initiation, be sure to send every part to every max7219 and then upload it. For example, if you have 5 max7219's, you have to send the scanLimit 5 times before you load it-- other wise not every max7219 will get the data. the function maxInUse keeps track of this, just tell it how many max7219 you are using. */ int dataIn = 2; int load = 3; int clock = 4; int rele = 17; int buzzer = 8; int up = 14; int down = 15; int inicio = 16; int maxInUse = 1; //change this variable to set how many MAX7219's you'll use int e = 0; // just a variable int j = 0; int i = 0; int i1 = 0; int i2 = 1; int i3 = 1; int count=0; int pinArray[] = { 0x01, 0x02, 0x03, 0x04}; int val = 0; boolean start = 0; int m1 = 0; int m0 = 0; int s1 = 0; int s0 = 0; int minutos = 0; int segundos = 0; int tiempo = 240; // 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 = 0x08; byte max7219_reg_digit7 = 0x01; 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; /*int valor[] = { 0xED,0x05,0x7C,0x5D,0x95,0xD9,0xF9,0x0D,0xFD,0xDD};*/ int valor[] = { 126,48,109,121,51,91,95,112,127,123,0}; 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 shit 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 adressing different MAX7219's, whilele 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 shit digitalWrite(load,HIGH); } void setup () { pinMode(dataIn, OUTPUT); pinMode(clock, OUTPUT); pinMode(load, OUTPUT); pinMode(rele, OUTPUT); pinMode(buzzer, OUTPUT); pinMode(up, INPUT); pinMode(down, INPUT); pinMode(inicio, INPUT); Serial.begin(9600); digitalWrite(rele, LOW); digitalWrite(buzzer, LOW); digitalWrite(up, HIGH); digitalWrite(down, HIGH); digitalWrite(inicio, 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 calcula(); } void loop () { for (int i=1; i<=5; i++) { // empty registers, turn all LEDs off if (!digitalRead(inicio)) start=1; else if (!digitalRead(up)) tiempo=tiempo+30; else if ((tiempo >0)&&(!digitalRead(down))) tiempo=tiempo-30; delay(200); maxSingle(1,valor[m1]); maxSingle(2,valor[m0]); maxSingle(3,valor[s1]); maxSingle(4,valor[s0]); calcula(); } if ((tiempo>0)&&(start==1)) { digitalWrite(rele,HIGH); tiempo=tiempo-1; } else if ((tiempo==0)&&(start==1)) { digitalWrite(rele,LOW); for (int i=1; i<=4; i++) { // empty registers, turn all LEDs off maxSingle(1,valor[0]); maxSingle(2,valor[0]); maxSingle(3,valor[0]); maxSingle(4,valor[0]); digitalWrite(buzzer,HIGH); delay(50); digitalWrite(buzzer,LOW); for (int e=1; e<=5; e++) { maxSingle(1,valor[0]); maxSingle(2,valor[0]); maxSingle(3,valor[0]); maxSingle(4,valor[0]); delay(500); maxSingle(1,valor[11]); maxSingle(2,valor[11]); maxSingle(3,valor[11]); maxSingle(4,valor[11]); delay(500); } } start=0; } } void off(void){ for (count=0;count<4;count++) { digitalWrite(pinArray[count], HIGH); } } void calcula(){ minutos=tiempo/60; segundos=tiempo%60; m1=minutos/10; m0=minutos%10; s1=segundos/10; s0=segundos%10; }