/* code for max 7219 from maxim, reduced and optimised for useing more then one 7219 in a row, ______________________________________ Code History: -------------- The orginal Code where written for the wiring board by: * Nicholas Zambetti and Dave Mellis * Interaction Design Institute Ivrea * Dec 2004 * http://www.potemkin.org/uploads/Wiring/MAX7219.txt The first modification by: * Marcus Hannerstig * 2006 * K3, malmš hšgskola * http://www.xlab.se | http://arduino.berlios.de The second modification by: * tomek ness * Feb 2007 * FH-Potsdam * http://design.fh-potsdam.de/ This Version is modified by: * michael shaub * Jul 2007 * LA_CA_USA * http://www.cageybirds.com/ * @acknowledgements: eric f. -if you just use one max7219 >>> use the funktion maxSingle to controll the little guy ---maxSingle(register (1-8), collum (0-255)) -if you useing more then one max7219 and they all should do the same >>> use the funktion maxAll ---maxAll(register (1-8), collum (0-255)) -if you useing more then one max7219 and just want to change some thing at one little guy >>> use the funktion maxOne ---maxOne(Max you wane controll (1== the first one), register (1-8), collum (0-255)) /* take care with the initiation you have to send every part to every max7219 and then upload it. so for example if you have 5 max7219, you have to send the scanLimit 5 times befor you load it, other wise not every max7219 will get the shit. maxInUse is keeping track of this, just tell him how many max7219 you are uesing */ int dataIn = 12; int load = 11; int clock = 10; int maxInUse = 8; //here you have to change this varialbe to how many max 7219 you want to use int e = 0; // just a varialble int count = 1; // a counting varialble int delayvar = 300; // a delay varialble // 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; 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 more easy way while just useing one 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) { // put the initialisation to all the max 7219 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 max wille having a couple of them casaded int c = 0; digitalWrite(load, LOW); // begin for ( c = maxInUse; c > maxNr; c--) { putByte(0); // means no opperation putByte(0); // means no opperation } putByte(reg); // specify register putByte(col);//((data & 0x01) * 256) + data >> 1); // put data for ( c =maxNr-1; c >= 1; c--) { putByte(0); // means no opperation putByte(0); // means no opperation } digitalWrite(load, LOW); // and load da shit digitalWrite(load,HIGH); } void setup () { pinMode(dataIn, OUTPUT); pinMode(clock, OUTPUT); pinMode(load, OUTPUT); beginSerial(9600); //1200, 2400, 4800, 9600, 19200, 38400, 57600 and 115200 bits per second 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 } void loop () { //------------------------------------ if you use just one max7219 he should look like this maxOne(1,1,255); maxOne(1,2,255); maxOne(1,3,255); maxOne(1,4,255); maxOne(1,5,255); maxOne(1,6,255); maxOne(1,7,255); maxOne(1,8,255); delay(delayvar); // count 2 maxOne(1,1,0); maxOne(1,2,0); maxOne(1,3,0); maxOne(1,4,0); maxOne(1,5,0); maxOne(1,6,0); maxOne(1,7,0); maxOne(1,8,0); delay(delayvar); // count 3 maxOne(1,1,0); maxOne(1,2,0); maxOne(1,3,8); maxOne(1,4,24); maxOne(1,5,8); maxOne(1,6,8); maxOne(1,7,28); maxOne(1,8,0); delay(delayvar); // count 4 maxOne(1,1,0); maxOne(1,2,0); maxOne(1,3,0); maxOne(1,4,0); maxOne(1,5,0); maxOne(1,6,0); maxOne(1,7,0); maxOne(1,8,0); delay(delayvar); // count 5 maxOne(1,1,0); maxOne(1,2,0); maxOne(1,3,60); maxOne(1,4,2); maxOne(1,5,28); maxOne(1,6,32); maxOne(1,7,62); maxOne(1,8,0); delay(delayvar); // count 6 maxOne(1,1,0); maxOne(1,2,0); maxOne(1,3,0); maxOne(1,4,0); maxOne(1,5,0); maxOne(1,6,0); maxOne(1,7,0); maxOne(1,8,0); delay(delayvar); // count 7 maxOne(1,1,0); maxOne(1,2,0); maxOne(1,3,60); maxOne(1,4,2); maxOne(1,5,28); maxOne(1,6,2); maxOne(1,7,60); maxOne(1,8,0); delay(delayvar); // count 8 maxOne(1,1,0); maxOne(1,2,0); maxOne(1,3,0); maxOne(1,4,0); maxOne(1,5,0); maxOne(1,6,0); maxOne(1,7,0); maxOne(1,8,0); delay(delayvar); // count 9 maxOne(1,1,0); maxOne(1,2,0); maxOne(1,3,36); maxOne(1,4,36); maxOne(1,5,62); maxOne(1,6,4); maxOne(1,7,4); maxOne(1,8,0); delay(delayvar); // count 10 maxOne(1,1,0); maxOne(1,2,0); maxOne(1,3,0); maxOne(1,4,0); maxOne(1,5,0); maxOne(1,6,0); maxOne(1,7,0); maxOne(1,8,0); delay(delayvar); // count 11 maxOne(1,1,0); maxOne(1,2,0); maxOne(1,3,62); maxOne(1,4,32); maxOne(1,5,60); maxOne(1,6,2); maxOne(1,7,60); maxOne(1,8,0); delay(delayvar); // count 12 maxOne(1,1,0); maxOne(1,2,0); maxOne(1,3,0); maxOne(1,4,0); maxOne(1,5,0); maxOne(1,6,0); maxOne(1,7,0); maxOne(1,8,0); delay(delayvar); // count 13 maxOne(1,1,0); maxOne(1,2,0); maxOne(1,3,28); maxOne(1,4,32); maxOne(1,5,60); maxOne(1,6,34); maxOne(1,7,28); maxOne(1,8,0); delay(delayvar); // count 14 maxOne(1,1,0); maxOne(1,2,0); maxOne(1,3,0); maxOne(1,4,0); maxOne(1,5,0); maxOne(1,6,0); maxOne(1,7,0); maxOne(1,8,0); delay(delayvar); // count 15 maxOne(1,1,0); maxOne(1,2,0); maxOne(1,3,62); maxOne(1,4,2); maxOne(1,5,4); maxOne(1,6,8); maxOne(1,7,8); maxOne(1,8,0); delay(delayvar); // count 16 maxOne(1,1,0); maxOne(1,2,0); maxOne(1,3,0); maxOne(1,4,0); maxOne(1,5,0); maxOne(1,6,0); maxOne(1,7,0); maxOne(1,8,0); delay(delayvar); // count 17 maxOne(1,1,0); maxOne(1,2,0); maxOne(1,3,28); maxOne(1,4,34); maxOne(1,5,28); maxOne(1,6,34); maxOne(1,7,28); maxOne(1,8,0); delay(delayvar); // count 18 maxOne(1,1,0); maxOne(1,2,0); maxOne(1,3,0); maxOne(1,4,0); maxOne(1,5,0); maxOne(1,6,0); maxOne(1,7,0); maxOne(1,8,0); delay(delayvar); // count 19 maxOne(1,1,0); maxOne(1,2,0); maxOne(1,3,28); maxOne(1,4,34); maxOne(1,5,30); maxOne(1,6,2); maxOne(1,7,28); maxOne(1,8,0); delay(delayvar); // count 20 maxOne(1,1,0); maxOne(1,2,0); maxOne(1,3,0); maxOne(1,4,0); maxOne(1,5,0); maxOne(1,6,0); maxOne(1,7,0); maxOne(1,8,0); delay(delayvar); // count 21 maxOne(1,1,0); maxOne(1,2,0); maxOne(1,3,28); maxOne(1,4,38); maxOne(1,5,42); maxOne(1,6,50); maxOne(1,7,28); maxOne(1,8,0); delay(delayvar); // count 22 maxOne(1,1,0); maxOne(1,2,0); maxOne(1,3,0); maxOne(1,4,0); maxOne(1,5,0); maxOne(1,6,0); maxOne(1,7,0); maxOne(1,8,0); }