Advertisement
Guest User

flame.ino

a guest
Nov 4th, 2014
504
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.35 KB | None | 0 0
  1. int cs = 10;
  2. int clk = 13;
  3. int dataIn = 11;
  4. int maxInUse = 1;    //to set how many MAX7219's you'll use
  5. int e = 0;          
  6. int i = 0;
  7. int j = 0;
  8.                      // define max7219 registers
  9. byte max7219_reg_noop        = 0x00;
  10. byte max7219_reg_digit0      = 0x01;
  11. byte max7219_reg_digit1      = 0x02;
  12. byte max7219_reg_digit2      = 0x03;
  13. byte max7219_reg_digit3      = 0x04;
  14. byte max7219_reg_digit4      = 0x05;
  15. byte max7219_reg_digit5      = 0x06;
  16. byte max7219_reg_digit6      = 0x07;
  17. byte max7219_reg_digit7      = 0x08;
  18. byte max7219_reg_decodeMode  = 0x09;
  19. byte max7219_reg_intensity   = 0x0a;
  20. byte max7219_reg_scanLimit   = 0x0b;
  21. byte max7219_reg_shutdown    = 0x0c;
  22. byte max7219_reg_displayTest = 0x0f;
  23.  
  24. void putByte(byte data) {
  25.   byte i = 8;
  26.   byte mask;
  27.   while(i > 0) {
  28.     mask = 0x01 << (i - 1);      // get bitmask
  29.     digitalWrite( clk, LOW);   // tick,
  30.     if (data & mask){            // choose bit
  31.       digitalWrite(dataIn, HIGH);// send 1
  32.     }else{
  33.       digitalWrite(dataIn, LOW); // send 0
  34.     }
  35.     digitalWrite(clk, HIGH);   // tock
  36.     --i;                         // move to lesser bit
  37.   }
  38. }
  39.  
  40. void maxSingle( byte reg, byte col) {    
  41.   digitalWrite(cs, LOW);       // begin    
  42.   putByte(reg);                  // specify register
  43.   putByte(col);  
  44.   digitalWrite(cs, LOW);      
  45.   digitalWrite(cs,HIGH);
  46. }
  47.  
  48. void maxAll (byte reg, byte col) {    
  49.   int c = 0;
  50.   digitalWrite(cs, LOW);  // begin    
  51.   for ( c =1; c<= maxInUse; c++) {
  52.   putByte(reg);  // specify register
  53.   putByte(col);
  54.     }
  55.   digitalWrite(cs, LOW);
  56.   digitalWrite(cs,HIGH);
  57. }
  58.  
  59. void maxInit(){
  60.   maxAll(max7219_reg_scanLimit, 0x07);      
  61.   maxAll(max7219_reg_decodeMode, 0x00);  // using an led matrix
  62.   maxAll(max7219_reg_shutdown, 0x01);    // not in shutdown mode
  63.   maxAll(max7219_reg_displayTest, 0x00); // no display test
  64.    for (e=1; e<=8; e++) {maxAll(e,0);} // LEDs Off
  65.   maxAll(max7219_reg_intensity, 0x04 & 0x0f);
  66. }
  67.  
  68. void setup () {
  69.   pinMode(dataIn,  OUTPUT);
  70.   pinMode(clk,   OUTPUT);
  71.   pinMode(cs,    OUTPUT);
  72.   maxInit();  
  73. j=0;
  74.  
  75. }  
  76.  
  77. void loop () {
  78.  
  79. byte flamme[]={B11101110,
  80.                B01101100,
  81.                B00010010,
  82.                B00110010,
  83.                B01110110,
  84.                B01110111,
  85.                B01110110,
  86.                B01111100,
  87.                B10111000,              
  88.                B00000000,
  89.                B11001100,
  90.                B10001110,
  91.                B11001110,
  92.                B11101111,
  93.                B00110111,
  94.                B11000011,
  95.                B11100011,
  96.                B11010011,
  97.                B11110110,
  98.                B00111110,
  99.                B01111100,
  100.                B11101100,
  101.                B01001000,
  102.                B00111100,
  103.                B01111000,
  104.                B00111001,
  105.                B01111100,
  106.                B01111110,
  107.                B11111100,
  108.                B11011010,
  109.                B01101000,
  110.                B00110000,
  111.                B00000000,
  112.                B00000000,
  113.                B10110000,
  114.                B10111010,
  115.                B11100100,
  116.                B11001110,
  117.                B11101110,
  118.                B01101100,
  119.                B00010010,
  120.                B00110010,
  121.                B10011000,
  122.                B10111100,
  123.                B11110010,
  124.                B11100100,
  125.                B00111000,
  126.                B01111100,
  127.                B11101110,
  128.                B11101110,
  129.                B11000111,
  130.                B11000011,
  131.                B00000010,
  132.                B00000000,
  133.                B00000000,
  134.                B11001100,
  135.                B10001110,
  136.                B11001110,
  137.                B11101111,
  138.                B00110111,
  139.                B11000011,
  140.                B11100011,
  141.                B11010011,
  142.                B11110110,
  143.                B00111110,
  144.                B01111100,
  145.                B11101100,
  146.                B01001000,
  147.                B00111100,
  148.                B01111000,
  149.                B00111001,
  150.                B01111100,
  151.                B01111110,
  152.                B11111100,
  153.                B11011010,
  154.                B01101000,
  155.                B00110000,
  156.                B10110000,
  157.                B10111010,
  158.                B11100100,
  159.                B11001110,
  160.                B11101110,
  161.                B01101100,
  162.                B00010010,
  163.                B00110010,
  164.                B11000010,
  165.                B11100111,
  166.                B00110110,
  167.                B11000100,
  168.                B11000110,
  169.                B10010011,
  170.                B00010110,
  171.                B00111110,
  172.                B01111100,
  173.                B11100100,
  174.                B01000000,
  175.                B01111001,
  176.                B01111001,
  177.                B00111001,
  178.                B11111100,
  179.                B01111100,
  180.                B11001100,
  181.                B11011000,
  182.                B01111100,
  183.                B00111100,
  184.                B00111100,
  185.                B00111000,
  186.                B01110000,
  187.                B11000001,
  188.                B01100100,
  189.                B00000000,
  190.                B00110011,
  191.                B11101110,
  192.                B01101100,
  193.                B00010010,
  194.                B00110010,
  195.                B01110110,
  196.                B01110111,
  197.                B01110110,
  198.                B01111100,
  199.                B10111000,
  200.                B10011000,
  201.                B10001100,
  202.                B11000010,
  203.                B11100100,
  204.                B00111000,
  205.                B01111100,
  206.                B11101110,
  207.                B11101110,
  208.                B11011111,
  209.                B11111011,
  210.                B11100010,
  211.                B11100000,
  212.                B11000010,
  213.                B11100111,
  214.                B00100011,
  215.                B11000001,
  216.                B11000011,
  217.                B00000000,
  218.                B11001100,
  219.                B10001110,
  220.                B11001110,
  221.                B11101111,
  222.                B00110111,
  223.                B11000011,
  224.                B11100011,
  225.                B11010011,
  226.                B11110110,
  227.                B00111110,
  228.                B01111100,
  229.                B11101100,
  230.                B01001000,
  231.                B00111100,
  232.                B01111000,
  233.                B00111001,
  234.                B01111100,
  235.                B01111110,
  236.                B11111100,
  237.                B11011010,
  238.                B01101000,
  239.                B00110000,
  240.                B10110000,
  241.                B10111010,
  242.                B11100100,
  243.                B11001110,
  244.                B11101110,
  245.                B01101100,
  246.                B00010010,
  247.                B00110010,
  248.                B00000000,
  249.                B00110000,
  250.                B01110100,
  251.                B01110111,
  252.                B11110110,
  253.                B01111110,
  254.                B00111100,
  255.                B00011100,
  256.                B00001110,
  257.                B00010110,
  258.                B00000000,
  259.                B11001100,
  260.                B10001110,
  261.                B11001110,
  262.                B11101111,
  263.                B00110111,
  264.                B11000011,
  265.                B11100011,
  266.                B11010011,
  267.                B11110110,
  268.                B00111110,
  269.                B01111100,
  270.                B11101100,
  271.                B01001000,
  272.                B00111100,
  273.                B01111000,
  274.                B00111001,
  275.                B01111100,
  276.                B01111110,
  277.                B11111100,
  278.                B11011010,
  279.                B01101000,
  280.                B00110000,
  281.                B10110000,
  282.                B10111010,
  283.                B11100100,
  284.                B11001110,
  285.                B11101110,
  286.                B01101100,
  287.                B00010010,
  288.                B00110010,
  289.                B01110110,
  290.                B01110111,
  291.                B01110110,
  292.                B01111100,
  293.                B11111000,
  294.                B10011000,
  295.                B10001100,
  296.                B11001110,
  297.                B11111100,
  298.                B00111000,
  299.                B01111100,
  300.                B11101110,
  301.                B11101110,
  302.                B11000111,
  303.                B11000011,
  304.                B10000010,
  305.                B10000000,
  306.                B11000010,
  307.                B11100111,
  308.                B00111011,
  309.                B11011011,
  310.                B11011011,
  311.                B10110011,
  312.                B10111011,
  313.                B01111110,
  314.                B00111100,
  315.                B00110000,
  316.                B10011000,
  317.                B10001100,
  318.                B11001110,
  319.                B11111100,
  320.                B00111000,
  321.                B01111100,
  322.                B11101110,
  323.                B11101110,
  324.                B11000111,
  325.                B11000011,
  326.                B10000010,
  327.                B10000000,
  328.                B11000010,
  329.                B11100111,
  330.                B00111011,
  331.                B11011011,
  332.                B11011011,
  333.                B10110011,
  334.                B10111011,
  335.                B01111110,
  336.                B00111100,
  337.                B00110000,
  338.                B01110010,
  339.                B01110111,
  340.                B11110110,
  341.                B11111100,
  342.                B01111000,
  343.                B00111000,
  344.                B00011100,
  345.                B00001110,
  346.                B00111010,
  347.                B01111001             };
  348.  
  349. for (i = 0; i < 9; i=i+1){maxSingle(i,flamme[j+i]);}
  350. delay(25);
  351. j = (j + 1)%260; // the Flame array contains 260 rows.
  352. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement