Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int cs = 10;
- int clk = 13;
- int dataIn = 11;
- int maxInUse = 1; //to set how many MAX7219's you'll use
- int e = 0;
- int i = 0;
- int j = 0;
- // 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( clk, LOW); // tick,
- if (data & mask){ // choose bit
- digitalWrite(dataIn, HIGH);// send 1
- }else{
- digitalWrite(dataIn, LOW); // send 0
- }
- digitalWrite(clk, HIGH); // tock
- --i; // move to lesser bit
- }
- }
- void maxSingle( byte reg, byte col) {
- digitalWrite(cs, LOW); // begin
- putByte(reg); // specify register
- putByte(col);
- digitalWrite(cs, LOW);
- digitalWrite(cs,HIGH);
- }
- void maxAll (byte reg, byte col) {
- int c = 0;
- digitalWrite(cs, LOW); // begin
- for ( c =1; c<= maxInUse; c++) {
- putByte(reg); // specify register
- putByte(col);
- }
- digitalWrite(cs, LOW);
- digitalWrite(cs,HIGH);
- }
- void maxInit(){
- maxAll(max7219_reg_scanLimit, 0x07);
- maxAll(max7219_reg_decodeMode, 0x00); // using an led matrix
- maxAll(max7219_reg_shutdown, 0x01); // not in shutdown mode
- maxAll(max7219_reg_displayTest, 0x00); // no display test
- for (e=1; e<=8; e++) {maxAll(e,0);} // LEDs Off
- maxAll(max7219_reg_intensity, 0x04 & 0x0f);
- }
- void setup () {
- pinMode(dataIn, OUTPUT);
- pinMode(clk, OUTPUT);
- pinMode(cs, OUTPUT);
- maxInit();
- j=0;
- }
- void loop () {
- byte flamme[]={B11101110,
- B01101100,
- B00010010,
- B00110010,
- B01110110,
- B01110111,
- B01110110,
- B01111100,
- B10111000,
- B00000000,
- B11001100,
- B10001110,
- B11001110,
- B11101111,
- B00110111,
- B11000011,
- B11100011,
- B11010011,
- B11110110,
- B00111110,
- B01111100,
- B11101100,
- B01001000,
- B00111100,
- B01111000,
- B00111001,
- B01111100,
- B01111110,
- B11111100,
- B11011010,
- B01101000,
- B00110000,
- B00000000,
- B00000000,
- B10110000,
- B10111010,
- B11100100,
- B11001110,
- B11101110,
- B01101100,
- B00010010,
- B00110010,
- B10011000,
- B10111100,
- B11110010,
- B11100100,
- B00111000,
- B01111100,
- B11101110,
- B11101110,
- B11000111,
- B11000011,
- B00000010,
- B00000000,
- B00000000,
- B11001100,
- B10001110,
- B11001110,
- B11101111,
- B00110111,
- B11000011,
- B11100011,
- B11010011,
- B11110110,
- B00111110,
- B01111100,
- B11101100,
- B01001000,
- B00111100,
- B01111000,
- B00111001,
- B01111100,
- B01111110,
- B11111100,
- B11011010,
- B01101000,
- B00110000,
- B10110000,
- B10111010,
- B11100100,
- B11001110,
- B11101110,
- B01101100,
- B00010010,
- B00110010,
- B11000010,
- B11100111,
- B00110110,
- B11000100,
- B11000110,
- B10010011,
- B00010110,
- B00111110,
- B01111100,
- B11100100,
- B01000000,
- B01111001,
- B01111001,
- B00111001,
- B11111100,
- B01111100,
- B11001100,
- B11011000,
- B01111100,
- B00111100,
- B00111100,
- B00111000,
- B01110000,
- B11000001,
- B01100100,
- B00000000,
- B00110011,
- B11101110,
- B01101100,
- B00010010,
- B00110010,
- B01110110,
- B01110111,
- B01110110,
- B01111100,
- B10111000,
- B10011000,
- B10001100,
- B11000010,
- B11100100,
- B00111000,
- B01111100,
- B11101110,
- B11101110,
- B11011111,
- B11111011,
- B11100010,
- B11100000,
- B11000010,
- B11100111,
- B00100011,
- B11000001,
- B11000011,
- B00000000,
- B11001100,
- B10001110,
- B11001110,
- B11101111,
- B00110111,
- B11000011,
- B11100011,
- B11010011,
- B11110110,
- B00111110,
- B01111100,
- B11101100,
- B01001000,
- B00111100,
- B01111000,
- B00111001,
- B01111100,
- B01111110,
- B11111100,
- B11011010,
- B01101000,
- B00110000,
- B10110000,
- B10111010,
- B11100100,
- B11001110,
- B11101110,
- B01101100,
- B00010010,
- B00110010,
- B00000000,
- B00110000,
- B01110100,
- B01110111,
- B11110110,
- B01111110,
- B00111100,
- B00011100,
- B00001110,
- B00010110,
- B00000000,
- B11001100,
- B10001110,
- B11001110,
- B11101111,
- B00110111,
- B11000011,
- B11100011,
- B11010011,
- B11110110,
- B00111110,
- B01111100,
- B11101100,
- B01001000,
- B00111100,
- B01111000,
- B00111001,
- B01111100,
- B01111110,
- B11111100,
- B11011010,
- B01101000,
- B00110000,
- B10110000,
- B10111010,
- B11100100,
- B11001110,
- B11101110,
- B01101100,
- B00010010,
- B00110010,
- B01110110,
- B01110111,
- B01110110,
- B01111100,
- B11111000,
- B10011000,
- B10001100,
- B11001110,
- B11111100,
- B00111000,
- B01111100,
- B11101110,
- B11101110,
- B11000111,
- B11000011,
- B10000010,
- B10000000,
- B11000010,
- B11100111,
- B00111011,
- B11011011,
- B11011011,
- B10110011,
- B10111011,
- B01111110,
- B00111100,
- B00110000,
- B10011000,
- B10001100,
- B11001110,
- B11111100,
- B00111000,
- B01111100,
- B11101110,
- B11101110,
- B11000111,
- B11000011,
- B10000010,
- B10000000,
- B11000010,
- B11100111,
- B00111011,
- B11011011,
- B11011011,
- B10110011,
- B10111011,
- B01111110,
- B00111100,
- B00110000,
- B01110010,
- B01110111,
- B11110110,
- B11111100,
- B01111000,
- B00111000,
- B00011100,
- B00001110,
- B00111010,
- B01111001 };
- for (i = 0; i < 9; i=i+1){maxSingle(i,flamme[j+i]);}
- delay(25);
- j = (j + 1)%260; // the Flame array contains 260 rows.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement