Advertisement
Badjer1983

Star Wars Chest Box LED Matrix

Dec 7th, 2017
258
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. unsigned char i;
  2. unsigned char j;
  3.  
  4. int Max7219_pinCLK = 10;
  5. int Max7219_pinCS = 9;
  6. int Max7219_pinDIN = 8;
  7.  
  8. unsigned char disp1[19][8]={0x0c,0x1e,0x3e,0x7c,0x7c,0x3e,0x1e,0x0c};
  9.  
  10. void Write_Max7219_byte(unsigned char DATA)
  11. {  
  12.   unsigned char i;
  13.   digitalWrite(Max7219_pinCS,LOW);  
  14.   for(i=8;i>=1;i--)
  15.   {    
  16.     digitalWrite(Max7219_pinCLK,LOW);
  17.     digitalWrite(Max7219_pinDIN,DATA&0x80);
  18.     DATA = DATA<<1;
  19.     digitalWrite(Max7219_pinCLK,HIGH);
  20.   }                                
  21. }
  22.  
  23. void Write_Max7219(unsigned char address,unsigned char dat)
  24. {
  25.   digitalWrite(Max7219_pinCS,LOW);
  26.   Write_Max7219_byte(address);          
  27.   Write_Max7219_byte(dat);              
  28.   digitalWrite(Max7219_pinCS,HIGH);
  29. }
  30.  
  31. void Init_MAX7219(void)
  32. {
  33.   Write_Max7219(0x09, 0x00);      
  34.   Write_Max7219(0x0a, 0x03);      
  35.   Write_Max7219(0x0b, 0x07);      
  36.   Write_Max7219(0x0c, 0x01);      
  37.   Write_Max7219(0x0f, 0x00);      
  38. }
  39.  
  40. void setup()
  41. {
  42.  
  43.   pinMode(Max7219_pinCLK,OUTPUT);
  44.   pinMode(Max7219_pinCS,OUTPUT);
  45.   pinMode(Max7219_pinDIN,OUTPUT);
  46.   delay(50);
  47.   Init_MAX7219();
  48. }
  49.  
  50. void loop()
  51. {
  52.   for(j=0;j<19;j++)
  53.   {
  54.     for(i=1;i<9;i++)
  55.       Write_Max7219(i,disp1[j][i-1]);
  56.     delay(100);
  57.   }  
  58. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement