极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 13769|回复: 12

32*16 RGB LED点阵32*16 RGB LED点阵

[复制链接]
发表于 2013-6-12 23:01:07 | 显示全部楼层 |阅读模式
老外设计的32*16 RGB LED点阵
看看Youtube。LED置入乒乓球里,变成大屏幕了










  1. /*-------------------------------------------------------------------------------------------------------------------------------------------*/

  2. //Definitions
  3. #define number_of_gray_scale_values 4 // corresponds to 6 Gray-Scale-Levels

  4. #define Latch      2 // PIN number on PORTC
  5. #define Clock      1 // PIN number on PORTC
  6. #define Enable     0 // PIN number on PORTC
  7. #define Clear      3 // PIN number on PORTC
  8. #define Debug      2 // PIN number on PORTB

  9. #define Data_r_u   2 // PIN number on PORTD
  10. #define Data_g_u   3 // PIN number on PORTD
  11. #define Data_b_u   4 // PIN number on PORTD
  12. #define Data_z_u   5 // PIN number on PORTD
  13. #define Data_r_d   6 // PIN number on PORTD
  14. #define Data_g_d   7 // PIN number on PORTD
  15. #define Data_b_d   0 // PIN number on PORTB
  16. #define Data_z_d   1 // PIN number on PORTB

  17. #define Latch_Low       PORTC &=  ~(1 << Latch)
  18. #define Latch_High      PORTC |=   (1 << Latch)
  19. #define Clock_Low       PORTC &=  ~(1 << Clock)
  20. #define Clock_High      PORTC |=   (1 << Clock)
  21. #define Enable_Low      PORTC &=  ~(1 << Enable)
  22. #define Enable_High     PORTC |=   (1 << Enable)
  23. #define Clear_Low       PORTC &=  ~(1 << Clear)
  24. #define Clear_High      PORTC |=   (1 << Clear)
  25. #define Debug_Low       PORTB &=  ~(1 << Debug)
  26. #define Debug_High      PORTB |=   (1 << Debug)

  27. #define Data_r_u_Low    PORTD &=  ~(1 << Data_r_u)
  28. #define Data_r_u_High   PORTD |=   (1 << Data_r_u)
  29. #define Data_g_u_Low    PORTD &=  ~(1 << Data_g_u)
  30. #define Data_g_u_High   PORTD |=   (1 << Data_g_u)
  31. #define Data_b_u_Low    PORTD &=  ~(1 << Data_b_u)
  32. #define Data_b_u_High   PORTD |=   (1 << Data_b_u)
  33. #define Data_z_u_Low    PORTD &=  ~(1 << Data_z_u)
  34. #define Data_z_u_High   PORTD |=   (1 << Data_z_u)
  35. #define Data_r_d_Low    PORTD &=  ~(1 << Data_r_d)
  36. #define Data_r_d_High   PORTD |=   (1 << Data_r_d)
  37. #define Data_g_d_Low    PORTD &=  ~(1 << Data_g_d)
  38. #define Data_g_d_High   PORTD |=   (1 << Data_g_d)
  39. #define Data_b_d_Low    PORTB &=  ~(1 << Data_b_d)
  40. #define Data_b_d_High   PORTB |=   (1 << Data_b_d)
  41. #define Data_z_d_Low    PORTB &=  ~(1 << Data_z_d)
  42. #define Data_z_d_High   PORTB |=   (1 << Data_z_d)

  43. /*-------------------------------------------------------------------------------------------------------------------------------------------*/

  44. //Global variables
  45. unsigned char dispmem[512];          //Display Memory
  46. static unsigned char *ptr_dispmem;   //Pointer to Display Memory used in ISR-Funktion

  47. //Color-Look-Up-Table for full Color Scale --> 216 colors (6xR + 6xG + 6xB)
  48. unsigned char LUT_r[216];
  49. unsigned char LUT_g[216];
  50. unsigned char LUT_b[216];

  51. //Reduced Color-Look-Up-Table - Contains only Colors within the topmost Color-Cycle
  52. unsigned char LUT_r_reduced[30];
  53. unsigned char LUT_g_reduced[30];
  54. unsigned char LUT_b_reduced[30];

  55. //Pointers to dispmem
  56. static unsigned char *ptr_dispmem_u;
  57. static unsigned char *ptr_dispmem_d;
  58.   
  59. unsigned char compare_value = 0;
  60. unsigned char row = 0;
  61. unsigned char x   = 0;

  62. byte remote = 0;

  63. /*-------------------------------------------------------------------------------------------------------------------------------------------*/

  64. //Initialize USART Comunication
  65. void uart_init(void)
  66. {
  67.   UCSR0A |= (1<<U2X0);                                 // Double up UART
  68.   UCSR0B |= (1<<RXEN0)  | (1<<TXEN0) | (1<<RXCIE0);    // UART RX, TX und RX Interrupt enable
  69.   UCSR0C |= (1<<UCSZ01) | (1<<UCSZ00)             ;    // Asynchrous 8N1

  70.   UBRR0H = 0;
  71.   UBRR0L = 16; //Baud Rate 115200   --> 2.1% Error at 16MHz
  72. }

  73. /*-------------------------------------------------------------------------------------------------------------------------------------------*/

  74. //Initialize Look Up Tables
  75. void LUT_init(void)
  76. {
  77.   //Full LUT with 216 colors
  78.   for (byte i = 0; i < 216; i++)
  79.   {
  80.     LUT_r[i] = (byte)(i/36);
  81.     LUT_g[i] = (byte)((i%36)/6);
  82.     LUT_b[i] = i%6;
  83.   }
  84.   
  85.   //Reduced LUT with 30 colors
  86.   for (byte k=0; k<5; k++)
  87.   {
  88.     LUT_r_reduced[k     ] =   5; // R: 5
  89.     LUT_g_reduced[k     ] = k+1; // G: 1 --> 5
  90.     LUT_b_reduced[k     ] =   0; // B: 0

  91.     LUT_r_reduced[5  + k] = 4-k; // R: 4 --> 0
  92.     LUT_g_reduced[5  + k] =   5; // G: 5
  93.     LUT_b_reduced[5  + k] =   0; // B: 0
  94.             
  95.     LUT_r_reduced[10 + k] =   0; // R: 0
  96.     LUT_g_reduced[10 + k] =   5; // G: 5
  97.     LUT_b_reduced[10 + k] = k+1; // B: 1 --> 5
  98.    
  99.     LUT_r_reduced[15 + k] =   0; // R: 0
  100.     LUT_g_reduced[15 + k] = 4-k; // G: 4 --> 0
  101.     LUT_b_reduced[15 + k] =   5; // B: 5
  102.               
  103.     LUT_r_reduced[20 + k] = k+1; // R: 1 --> 5
  104.     LUT_g_reduced[20 + k] =   0; // G: 0
  105.     LUT_b_reduced[20 + k] =   5; // B: 5      
  106.             
  107.     LUT_r_reduced[25 + k] =   5; // R: 5
  108.     LUT_g_reduced[25 + k] =   0; // G: 0
  109.     LUT_b_reduced[25 + k] = 4-k; // B: 4 --> 0
  110.   }
  111. }

  112. /*-------------------------------------------------------------------------------------------------------------------------------------------*/

  113. //Interrupt Service Function which is called everytime a byte is recieved
  114. ISR(USART_RX_vect)
  115. {
  116.   unsigned char b;
  117.   b=UDR0;
  118.   if (b == 255) {ptr_dispmem = dispmem;}
  119.   else
  120.   {
  121.     *ptr_dispmem = b;
  122.     ptr_dispmem++;
  123.   }
  124. }

  125. /*-------------------------------------------------------------------------------------------------------------------------------------------*/

  126. //Refresh Function - refreshes one ROW each time called (time apprx. 175 猀)
  127. void refresh_leds(void)
  128. {  
  129.   unsigned char temp_u;
  130.   unsigned char temp_d;
  131.                     
  132.   //Clear Latch
  133.   Latch_Low;
  134.         
  135.   for (x = 0; x < 32; x++)
  136.   {                    
  137.     //Clear Clock in advance      
  138.     Clock_Low;
  139.    
  140.     //Clear all Data Outputs in advance
  141.     PORTD &=  B00000011;
  142.     PORTB &=  B11111100;
  143.                
  144.     //Copy current color value only once from dispmem
  145.     temp_u = *ptr_dispmem_u;
  146.     temp_d = *ptr_dispmem_d;
  147.    
  148.     //Set Data Outputs if necessary
  149.     if (LUT_r[temp_u] > compare_value) {Data_r_u_High;}
  150.     if (LUT_g[temp_u] > compare_value) {Data_g_u_High;}
  151.     if (LUT_b[temp_u] > compare_value) {Data_b_u_High;}
  152.    
  153.     if (LUT_r[temp_d] > compare_value) {Data_r_d_High;}
  154.     if (LUT_g[temp_d] > compare_value) {Data_g_d_High;}
  155.     if (LUT_b[temp_d] > compare_value) {Data_b_d_High;}
  156.    
  157.     if ((x == row) || (x == row + 8) || (x == row + 16) || (x == row + 24)) {Data_z_u_High; Data_z_d_High;}
  158.     if (row == 8) {Data_z_u_Low; Data_z_d_Low;}
  159.    
  160.     //Set Clock and thus shift out current bits
  161.     Clock_High;
  162.    
  163.     //Increment Pointers                  
  164.     ptr_dispmem_u++;
  165.     ptr_dispmem_d++;   
  166.   }
  167.   
  168.   //Set Latch
  169.   Latch_High;
  170.   
  171.   //Row is done --> Increment Row Number
  172.   row++;
  173.   
  174.   //If Frame is done
  175.   if (row == 9)
  176.   {
  177.     row = 0;
  178.     ptr_dispmem_u = dispmem;
  179.     ptr_dispmem_d = dispmem + 256;
  180.     compare_value++;
  181.     if (compare_value > number_of_gray_scale_values) {compare_value = 0;}
  182.   }
  183.   
  184. }

  185. /*-------------------------------------------------------------------------------------------------------------------------------------------*/

  186. /*-------------------------------------------------------------------------------------------------------------------------------------------*/

  187. //Does the same as the refresh-funcition above but with the reduced color LUT
  188. void refresh_leds_with_reduced_colors(void)
  189. {  
  190.   unsigned char temp_u;
  191.   unsigned char temp_d;
  192.                  
  193.   //Clear Latch
  194.   Latch_Low;
  195.       
  196.   for (x = 0; x < 32; x++)
  197.   {                    
  198.     //Clear Clock in advance      
  199.     Clock_Low;
  200.    
  201.     //Clear all Data Outputs in advance
  202.     PORTD &=  B00000011;
  203.     PORTB &=  B11111100;
  204.                
  205.     //Copy current color value only once from dispmem
  206.     temp_u = *ptr_dispmem_u;
  207.     temp_d = *ptr_dispmem_d;
  208.    
  209.     //Set Data Outputs if necessary
  210.     if (LUT_r_reduced[temp_u] > compare_value) {Data_r_u_High;}
  211.     if (LUT_g_reduced[temp_u] > compare_value) {Data_g_u_High;}
  212.     if (LUT_b_reduced[temp_u] > compare_value) {Data_b_u_High;}
  213.    
  214.     if (LUT_r_reduced[temp_d] > compare_value) {Data_r_d_High;}
  215.     if (LUT_g_reduced[temp_d] > compare_value) {Data_g_d_High;}
  216.     if (LUT_b_reduced[temp_d] > compare_value) {Data_b_d_High;}
  217.    
  218.     if ((x == row) || (x == row + 8) || (x == row + 16) || (x == row + 24)) {Data_z_u_High; Data_z_d_High;}
  219.     if (row == 8) {Data_z_u_Low; Data_z_d_Low;}
  220.    
  221.     //Set Clock and thus shift out current bits
  222.     Clock_High;
  223.    
  224.     //Increment Pointers                  
  225.     ptr_dispmem_u++;
  226.     ptr_dispmem_d++;   
  227.   }
  228.   
  229.   //Set Latch
  230.   Latch_High;
  231.   
  232.   //Row is done --> Increment Row Number
  233.   row++;
  234.   
  235.   //If Frame is done
  236.   if (row > 8)
  237.   {
  238.     row = 0;
  239.     ptr_dispmem_u = dispmem;
  240.     ptr_dispmem_d = dispmem + 256;
  241.     compare_value++;
  242.     if (compare_value > number_of_gray_scale_values) {compare_value = 0;}
  243.   }
  244.   
  245. }

  246. /*-------------------------------------------------------------------------------------------------------------------------------------------*/

  247. //Setup Function called once at the beginning
  248. void setup()
  249. {
  250.   
  251.   //Set PINs as OUTPUTs
  252.   DDRD = DDRD | B11111100;
  253.   DDRB = DDRB | B00000111;
  254.   DDRC = DDRC | B00001111;
  255.   
  256.   //Set Select_Button_Pin as Input
  257.   pinMode(19, INPUT);
  258.   delay(10);
  259.   if (digitalRead(19)) {remote = 1;}
  260.   
  261.   Debug_High;
  262.   delay(50);
  263.   Debug_Low;
  264.   
  265.   Enable_Low;
  266.   Clear_High;
  267.   
  268.   for (int i=0; i<512; i++){dispmem[i]=0;}
  269.   
  270.   uart_init();
  271.   LUT_init();
  272.   ptr_dispmem = dispmem;
  273.   
  274.   ptr_dispmem_u = dispmem;
  275.   ptr_dispmem_d = dispmem + 256;
  276.   
  277.   sei();
  278.   
  279. }

  280. /*-------------------------------------------------------------------------------------------------------------------------------------------*/

  281. //Loop Function called over and over again
  282. void loop()
  283. {
  284.   if (remote == 1)
  285.   {
  286.     refresh_leds();
  287.   }
  288.   else
  289.   {     
  290.     byte do_plasma = random(100);
  291.     //Plasma should be the most significant secence on the wall cause this is what it was made for, so 50% seems a fair number
  292.     if (do_plasma < 50)
  293.     {
  294.       plasma(random(5,40),random(25, 050));
  295.     }
  296.     //if sequence is not plasma than its randomly choosen from a repertoir
  297.     else
  298.     {
  299.       byte   sequence = random(4);
  300.       byte   duration = random(5,40);   //How long the sequence should last
  301.       byte frame_time = random(60,100); //Speed of the sequence
  302.       
  303.       switch (sequence)
  304.       {
  305.         case 0: falling_points(duration, frame_time); break;
  306.         case 1:  random_points(duration, frame_time); break;
  307.         case 2:           pong(duration, frame_time); break;
  308.         case 3:          boxes(duration, frame_time); break;
  309.       }
  310.     }
  311.   }
  312. }

  313. /*-------------------------------------------------------------------------------------------------------------------------------------------*/



  314. //Sequences//

  315. /*-------------------------------------------------------------------------------------------------------------------------------------------*/

  316. void plasma (unsigned long duration, unsigned long frame_time)
  317. {
  318.   //Variables
  319.   unsigned long end_time = millis() + (duration * 1000);
  320.   byte pixel_size_x = random(2,7);
  321.   byte pixel_size_y = random(2,7);
  322.    
  323.   //Pointer to frame
  324.   static unsigned char *ptr_frame;
  325.       
  326.   //Calculate Plasma Geometry only ONCE
  327.   for(byte y = 0; y < 16;  y++)
  328.   {
  329.     for(byte x = 0; x < 32; x++)
  330.     {
  331.       dispmem[y*32 + x] = (byte) ((15+15*(sin(((float)x)/pixel_size_x)) + 15+15*(sin(((float)y)/pixel_size_y))) / 2);
  332.     }
  333.   }
  334.    
  335.   do
  336.   {   
  337.     ptr_frame = dispmem;
  338.    
  339.     for (byte y = 0; y < 16; y++)
  340.     {
  341.       for (byte x = 0; x < 32; x++)
  342.       {
  343.         if (*ptr_frame == 29) {*ptr_frame = 0;} else {*ptr_frame = *ptr_frame + 1;}
  344.         ptr_frame++;
  345.       }
  346.     }
  347.    
  348.     unsigned long frame_end_time = millis() + frame_time;
  349.    
  350.     Enable_Low;
  351.    
  352.     while (frame_end_time > millis())
  353.     {
  354.       for (byte x=0; x<8; x++){refresh_leds_with_reduced_colors();}
  355.     }
  356.    
  357.     Enable_High;
  358.    
  359.   } while (millis() <= end_time);

  360.   //At the end of the plasma sequence fade all LEDs smoothly to red
  361.   frame_time = 80;
  362.   
  363.   for (byte c=0; c < 30; c++)
  364.   {
  365.     ptr_frame = dispmem;
  366.    
  367.     for (byte y = 0; y < 16; y++)
  368.     {
  369.       for (byte x = 0; x < 32; x++)
  370.       {
  371.         if (*ptr_frame < 29) {*ptr_frame = *ptr_frame + 1;}
  372.         ptr_frame++;
  373.       }
  374.     }
  375.    
  376.     unsigned long frame_end_time = millis() + frame_time;
  377.     Enable_Low;
  378.     while (frame_end_time > millis())
  379.     {
  380.       for (byte x=0; x<8; x++){refresh_leds_with_reduced_colors();}
  381.     }
  382.     Enable_High;
  383.   }
  384.   
  385. }

  386. /*-------------------------------------------------------------------------------------------------------------------------------------------*/

  387. /*-------------------------------------------------------------------------------------------------------------------------------------------*/

  388. void falling_points (unsigned long duration, unsigned long frame_time)
  389. {
  390.   //Variables
  391.   unsigned long end_time = millis() + (duration * 1000);
  392.   
  393.   //Clear Dispmem first
  394.   for (byte y = 0; y < 16; y++)
  395.   {
  396.     for (byte x = 0; x < 32; x++)
  397.     {
  398.       dispmem[y*32+x] = 0;
  399.     }
  400.   }
  401.             
  402.   do
  403.   {        

  404.     for (byte y = 15; y > 0; y--)
  405.     {
  406.       for (byte x = 0; x < 32; x++)
  407.       {
  408.         dispmem[y*32+x] = dispmem[(y-1)*32+x];
  409.       }
  410.     }
  411.    
  412.     for (byte i=0; i<32; i++) {dispmem[i] = 0;}
  413.    
  414.     byte dummy = random(100);

  415.     if (dummy <= 20) {dummy =  0;}
  416.     if (dummy >  20) {dummy =  3;}
  417.     if (dummy >  30) {dummy =  2;}
  418.     if (dummy >  40) {dummy =  5;}
  419.     if (dummy >  50) {dummy =  6;}
  420.     if (dummy >  60) {dummy =  7;}
  421.     if (dummy >  70) {dummy =  8;}
  422.     if (dummy >  80) {dummy =  9;}
  423.     if (dummy >  90) {dummy = 10;}
  424.    
  425.     for (byte i=0; i < dummy; i++)
  426.     {
  427.       dispmem[random(32)] = random(216);
  428.     }
  429.    
  430.     unsigned long frame_end_time = millis() + frame_time;
  431.     Enable_Low;
  432.     while (frame_end_time > millis())
  433.     {
  434.       for (byte x=0; x<8; x++){refresh_leds();}
  435.     }
  436.     Enable_High;
  437.       
  438.   } while (millis() <= end_time);
  439. }

  440. /*-------------------------------------------------------------------------------------------------------------------------------------------*/

  441. /*-------------------------------------------------------------------------------------------------------------------------------------------*/

  442. void pong (unsigned long duration, unsigned long frame_time)
  443. {
  444.   //Variables  
  445.   unsigned long end_time = millis() + (duration * 1000);
  446.   
  447.   //Pointer to frame
  448.   static unsigned char *ptr_frame;
  449.    
  450.   byte pos_x[7];
  451.   byte pos_y[7];
  452.   byte dir_x[7];
  453.   byte dir_y[7];
  454.   byte color[7];
  455.   
  456.   for (byte i=0; i<7; i++)
  457.   {
  458.     pos_x[i]=random(1,31);
  459.     pos_y[i]=random(1,15);
  460.     dir_x[i]=random(2);
  461.     dir_y[i]=random(2);
  462.     color[i]=random(215);
  463.   }
  464.    
  465.   do
  466.   {            
  467.     ptr_frame = dispmem;
  468.    
  469.     //clear matrix
  470.     for (byte y = 0; y < 16; y++)
  471.     {
  472.       for (byte x = 0; x < 32; x++)
  473.       {
  474.         *ptr_frame = 0;
  475.         ptr_frame++;
  476.       }
  477.     }
  478.    
  479.     for (byte i=0; i<7; i++)
  480.     {
  481.       if (dir_x[i] == 1)  {pos_x[i]++;} else {pos_x[i]--;}
  482.       if (dir_y[i] == 1)  {pos_y[i]++;} else {pos_y[i]--;}
  483.       if (pos_x[i] == 31) {dir_x[i] = 0;}
  484.       if (pos_y[i] == 15) {dir_y[i] = 0;}
  485.       if (pos_x[i] ==  0) {dir_x[i] = 1;}
  486.       if (pos_y[i] ==  0) {dir_y[i] = 1;}
  487.       dispmem[pos_y[i]*32+pos_x[i]] = color[i];
  488.     }
  489.       
  490.     unsigned long frame_end_time = millis() + frame_time;
  491.     Enable_Low;
  492.     while (frame_end_time > millis())
  493.     {
  494.       for (byte x=0; x<8; x++){refresh_leds();}
  495.     }
  496.     Enable_High;
  497.       
  498.   } while (millis() <= end_time);
  499. }

  500. /*-------------------------------------------------------------------------------------------------------------------------------------------*/

  501. /*-------------------------------------------------------------------------------------------------------------------------------------------*/

  502. void random_points (unsigned long duration, unsigned long frame_time)
  503. {
  504.   //Variables
  505.   unsigned long end_time = millis() + (duration * 1000);
  506.   byte number_of_points = random(5,20);
  507.   byte color_of_points[20];
  508.   
  509.   //Pointer to frame
  510.   static unsigned char *ptr_frame;
  511.          
  512.   for (byte i=0; i < number_of_points; i++)
  513.   {
  514.     color_of_points[i] = random(216);
  515.   }
  516.      
  517.   //Animate Points   
  518.   do
  519.   {   
  520.     ptr_frame = dispmem;
  521.    
  522.     //clear matrix
  523.     for (byte y = 0; y < 16; y++)
  524.     {
  525.       for (byte x = 0; x < 32; x++)
  526.       {
  527.         *ptr_frame = 0;
  528.         ptr_frame++;
  529.       }
  530.     }
  531.    
  532.     for (byte i=0; i < number_of_points; i++)
  533.     {
  534.       ptr_frame = dispmem + random(512);
  535.       *ptr_frame = color_of_points[i];
  536.     }
  537.    
  538.    
  539.     unsigned long frame_end_time = millis() + frame_time;
  540.     Enable_Low;
  541.     while (frame_end_time > millis())
  542.     {
  543.       for (byte x=0; x<8; x++){refresh_leds();}
  544.     }
  545.     Enable_High;
  546.    
  547.   } while (millis() <= end_time);  
  548. }

  549. /*-------------------------------------------------------------------------------------------------------------------------------------------*/

  550. /*-------------------------------------------------------------------------------------------------------------------------------------------*/

  551. void boxes (unsigned long duration, unsigned long frame_time)
  552. {
  553.   //Variables  
  554.   unsigned long end_time = millis() + (duration * 1000);
  555.   
  556.   //Pointer to frame
  557.   static unsigned char *ptr_frame;
  558.    
  559.   byte   pos[] = {0,2,4,6,8,10,12,10};
  560.   byte   dir[] = {1,1,1,1,1,1,0,0};
  561.   byte color[] = {180,210,30,35,5,185,180,210};
  562.         
  563.   do
  564.   {            
  565.     ptr_frame = dispmem;
  566.    
  567.     //clear matrix
  568.     for (byte y = 0; y < 16; y++)
  569.     {
  570.       for (byte x = 0; x < 32; x++)
  571.       {
  572.         *ptr_frame = 0;
  573.         ptr_frame++;
  574.       }
  575.     }
  576.    
  577.     for (byte i=0; i<8; i++)
  578.     {
  579.       if (dir[i] ==  1) {pos[i]++;} else {pos[i]--;}
  580.       if (pos[i] == 12) {dir[i] = 0;}
  581.       if (pos[i] ==  0) {dir[i] = 1;}
  582.       dispmem[(pos[i]+0)*32+4*i+0] = color[i];
  583.       dispmem[(pos[i]+0)*32+4*i+1] = color[i];
  584.       dispmem[(pos[i]+0)*32+4*i+2] = color[i];
  585.       dispmem[(pos[i]+0)*32+4*i+3] = color[i];
  586.       dispmem[(pos[i]+1)*32+4*i+0] = color[i];
  587.       dispmem[(pos[i]+1)*32+4*i+1] = color[i];
  588.       dispmem[(pos[i]+1)*32+4*i+2] = color[i];
  589.       dispmem[(pos[i]+1)*32+4*i+3] = color[i];
  590.       dispmem[(pos[i]+2)*32+4*i+0] = color[i];
  591.       dispmem[(pos[i]+2)*32+4*i+1] = color[i];
  592.       dispmem[(pos[i]+2)*32+4*i+2] = color[i];
  593.       dispmem[(pos[i]+2)*32+4*i+3] = color[i];
  594.       dispmem[(pos[i]+3)*32+4*i+0] = color[i];
  595.       dispmem[(pos[i]+3)*32+4*i+1] = color[i];
  596.       dispmem[(pos[i]+3)*32+4*i+2] = color[i];
  597.       dispmem[(pos[i]+3)*32+4*i+3] = color[i];   
  598.     }
  599.            
  600.     unsigned long frame_end_time = millis() + frame_time;
  601.     Enable_Low;
  602.     while (frame_end_time > millis())
  603.     {
  604.       for (byte x=0; x<8; x++){refresh_leds();}
  605.     }
  606.     Enable_High;
  607.       
  608.   } while (millis() <= end_time);
  609. }

  610. /*-------------------------------------------------------------------------------------------------------------------------------------------*/
复制代码
回复

使用道具 举报

发表于 2013-6-13 09:52:11 | 显示全部楼层
还得翻墙。。。
回复 支持 反对

使用道具 举报

发表于 2013-6-13 19:01:49 | 显示全部楼层
ro0t 发表于 2013-6-13 09:52
还得翻墙。。。

用web freer浏览器自带代理服务器
回复 支持 反对

使用道具 举报

发表于 2013-6-13 22:38:49 | 显示全部楼层
这次大家不用费心找这个教程了,例程都有了。。。。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-6-13 22:43:36 | 显示全部楼层
ro0t 发表于 2013-6-13 09:52
还得翻墙。。。

我是马来西亚人。为何要翻墙?
回复 支持 反对

使用道具 举报

发表于 2013-6-14 11:11:30 | 显示全部楼层
interrgned 发表于 2013-6-13 19:01
用web freer浏览器自带代理服务器

谢谢  我学习一下  
回复 支持 反对

使用道具 举报

发表于 2013-6-14 11:12:15 | 显示全部楼层
smching 发表于 2013-6-13 22:43
我是马来西亚人。为何要翻墙?

我在中国大陆。。。。。
回复 支持 反对

使用道具 举报

发表于 2013-6-14 14:26:20 | 显示全部楼层
他这是,三色点阵,每个595控制一种颜色,另一个595控制行,那是不是说列全部都接地了
还有,这个如何改成单色点阵的程序呢?最近刚好在研究这个
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-6-14 21:26:03 | 显示全部楼层
是的,全部列都得通过NPN晶体管接地,但並非同时接通,而是经过扫描方式接通。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-6-14 21:56:50 | 显示全部楼层
糯米基 发表于 2013-6-14 14:26
他这是,三色点阵,每个595控制一种颜色,另一个595控制行,那是不是说列全部都接地了
还有,这个如何改成 ...

我只找到8x848x8单色点阵

8x8单色点阵

  1. /*
  2. * _8x8 LED matrix
  3. *
  4. * (c) 2009 BlushingBoy.net
  5. */

  6. #include "TimerOne.h"

  7. byte rows[8] = {9, 14, 8, 12, 1, 7, 2, 5};
  8. byte cols[8] = {13, 3, 4, 10, 6, 11, 15, 16};
  9. byte pins[16] = {5, 4, 3, 2, 14, 15, 16, 17, 13, 12, 11, 10, 9, 8, 7, 6};
  10. byte screen[8] = {0, 0, 0, 0, 0, 0, 0, 0};
  11. volatile byte screenRow = 0;
  12. volatile byte screenCol = 0;

  13. void setup() {
  14.   Timer1.initialize(100);
  15.   for (int i = 2; i <= 17; i++)
  16.     pinMode(i, OUTPUT);
  17.   Timer1.attachInterrupt(doubleBuffer);
  18. }

  19. // interrupt routine
  20. void doubleBuffer() {
  21.   // reset the previous iteration
  22.   digitalWrite(translatePin(rows[screenRow]), HIGH); // set previous off
  23.   digitalWrite(translatePin(cols[screenCol]), LOW);  // set previous off
  24.   // go to the next iteration...
  25.   // go to the next screenCol, wrap if necessary
  26.   screenCol++;
  27.   if (screenCol >= 8) {
  28.     screenCol = 0;
  29.     // when screenCol wraps, go to the next screenRow, wrap if necessary
  30.     screenRow++;
  31.     if (screenRow >= 8) {
  32.       screenRow = 0;
  33.     }
  34.   }
  35.   // set this iteration
  36.   if((screen[screenRow]>>screenCol)&B1 == B1) {
  37.     digitalWrite(translatePin(rows[screenRow]), LOW);  // set this on
  38.     digitalWrite(translatePin(cols[screenCol]), HIGH); // set this on
  39.   } else {
  40.     digitalWrite(translatePin(rows[screenRow]), HIGH); // set this off
  41.     digitalWrite(translatePin(cols[screenCol]), LOW);  // set this off
  42.   }
  43. }

  44. byte translatePin(byte original) {
  45.   return pins[original - 1];
  46. }

  47. void allOFF() {
  48.   for (int i = 0; i < 8; i++)
  49.     screen[i]=0;
  50. }

  51. void on(byte row, byte column) {
  52.     screen[column-1] |= (B1<<(row-1));
  53. }

  54. void off(byte row, byte column) {
  55.     screen[column-1] &= ~(B1<<(row-1));
  56. }

  57. // looping some LEDs routine
  58. void loop() {
  59.   allOFF();
  60.   delay(1000);
  61.   on(3,3); on(3,4); on(3,5); on(3,6);
  62.   delay(400);
  63.   allOFF();
  64.   delay(1000);
  65.   on(4,4);
  66.   delay(400);
  67. }
复制代码



8x48单色点阵




  1. int x;
  2. int y;
  3. int latchPin1 = 5; //Arduino pin connected to blue 12 RCLK of 74HC595
  4. int clockPin1 = 6; //Arduino pin connected to green 11 SRCLK of 74HC595
  5. int dataPin1 = 7;  //Arduino pin connected to violet 14 SER of 74HC595

  6. //-- Rows (Positive Anodes) --
  7. int latchPin2 = 9; //Arduino pin connected to yellow Latch 12 RCLK of 74HC595
  8. int clockPin2 = 10; //Arduino pin connected to white Clock 11 SRCLK of 74HC595
  9. int dataPin2 = 8;  //Arduino pin connected to grey Data 14 SER of 74HC595

  10. //=== B I T M A P ===
  11. //Bits in this array represents one LED of the matrix
  12. // 8 is # of rows, 7 is # of LED matrix we have
  13. byte bitmap[8][7]; // Change the 7 to however many matrices you want to use.
  14. int numZones = sizeof(bitmap) / 8;
  15. int maxZoneIndex = numZones-1;
  16. int numCols = numZones * 8;

  17. byte alphabets[][5] = {
  18.   {0,0,0,0,0},
  19.   {31, 36, 68, 36, 31},
  20.   {127, 73, 73, 73, 54},
  21.   {62, 65, 65, 65, 34},
  22.   {127, 65, 65, 34, 28},
  23.   {127, 73, 73, 65, 65},
  24.   {127, 72, 72, 72, 64},
  25.   {62, 65, 65, 69, 38},
  26.   {127, 8, 8, 8, 127},
  27.   {0, 65, 127, 65, 0},
  28.   {2, 1, 1, 1, 126},
  29.   {127, 8, 20, 34, 65},
  30.   {127, 1, 1, 1, 1},
  31.   {127, 32, 16, 32, 127},
  32.   {127, 32, 16, 8, 127},
  33.   {62, 65, 65, 65, 62},
  34.   {127, 72, 72, 72, 48},
  35.   {62, 65, 69, 66, 61},
  36.   {127, 72, 76, 74, 49},
  37.   {50, 73, 73, 73, 38},
  38.   {64, 64, 127, 64, 64},
  39.   {126, 1, 1, 1, 126},
  40.   {124, 2, 1, 2, 124},
  41.   {126, 1, 6, 1, 126},
  42.   {99, 20, 8, 20, 99},
  43.   {96, 16, 15, 16, 96},
  44.   {67, 69, 73, 81, 97},
  45. };

  46. //=== S E T U P ===

  47. void setup() {
  48.   pinMode(latchPin1, OUTPUT);
  49.   pinMode(clockPin1, OUTPUT);
  50.   pinMode(dataPin1, OUTPUT);

  51.   pinMode(latchPin2, OUTPUT);
  52.   pinMode(clockPin2, OUTPUT);
  53.   pinMode(dataPin2, OUTPUT);

  54.   //-- Clear bitmap --
  55.   for (int row = 0; row > 8; row++) {
  56.     for (int zone = 0; zone <= maxZoneIndex; zone++) {
  57.       bitmap[row][zone] = 0;
  58.     }
  59.   }
  60. }

  61. //=== F U N C T I O N S ===
  62. // This routine takes whatever we've setup in the bitmap array and display it on the matrix
  63. void RefreshDisplay()
  64. {
  65.   for (int row = 0; row < 8; row++) {
  66.     int rowbit = 1 << row;
  67.     digitalWrite(latchPin2, LOW);  //Hold latchPin LOW for as long as we're transmitting data
  68.     shiftOut(dataPin2, clockPin2, MSBFIRST, rowbit);   //Transmit data

  69.     //-- Start sending column bytes --
  70.     digitalWrite(latchPin1, LOW);  //Hold latchPin LOW for as long as we're transmitting data

  71.     //-- Shift out to each matrix (zone is 8 columns represented by one matrix)
  72.     for (int zone = maxZoneIndex; zone >= 0; zone--) {
  73.       shiftOut(dataPin1, clockPin1, MSBFIRST, bitmap[row][zone]);
  74.     }

  75.     //-- Done sending Column bytes, flip both latches at once to eliminate flicker
  76.     digitalWrite(latchPin1, HIGH
  77.     digitalWrite(latchPin2, HIGH

  78.     //-- Wait a little bit to let humans see what we've pushed out onto the matrix --
  79.     delayMicroseconds(500);
  80.   }
  81. }

  82. // Converts row and colum to actual bitmap bit and turn it off/on
  83. void Plot(int col, int row, bool isOn)
  84. {
  85.   int zone = col / 8;
  86.   int colBitIndex = x % 8;
  87.   byte colBit = 1 << colBitIndex;
  88.   if (isOn)
  89.     bitmap[row][zone] =  bitmap[y][zone] | colBit;
  90.   else
  91.     bitmap[row][zone] =  bitmap[y][zone] & (~colBit);
  92. }
  93. // Plot each character of the message one column at a time, updated the display, shift bitmap left.
  94. void AlphabetSoup()
  95. {
  96.   char msg[] = "YOUR TEXT ";

  97.   for (int charIndex=0; charIndex < (sizeof(msg)-1); charIndex++)
  98.   {
  99.     int alphabetIndex = msg[charIndex] - '@';
  100.     if (alphabetIndex < 0) alphabetIndex=0;
  101.    
  102.     //-- Draw one character of the message --
  103.     for (int col = 0; col < 6; col++)
  104.     {
  105.       for (int row = 0; row < 8; row++)
  106.       {
  107.         bool isOn = 0;
  108.         if (col<5) isOn = bitRead( alphabets[alphabetIndex][col], 7-row ) == 1;
  109.         Plot( numCols-1, row, isOn
  110.       }
  111.      
  112.       //-- The more times you repeat this loop, the slower we would scroll --
  113.       for (int refreshCount=0; refreshCount < 7; refreshCount++) //change  this value to vary speed
  114.         RefreshDisplay();
  115.       //-- Shift the bitmap one column to left --
  116.       for (int row=0; row<8; row++)
  117.       {
  118.         for (int zone=0; zone < numZones; zone++)
  119.         {
  120.           bitmap[row][zone] = bitmap[row][zone] >> 1;
  121.                     // Roll over lowest bit from the next zone as highest bit of this zone.
  122.           if (zone < maxZoneIndex) bitWrite(bitmap[row][zone], 7,
  123. bitRead(bitmap[row][zone+1],0));
  124.         }
  125.       }
  126.     }
  127.   }
  128. }

  129. //=== L O O P ===
  130. void loop() {
  131.   AlphabetSoup();
  132. }
复制代码







回复 支持 反对

使用道具 举报

发表于 2013-6-16 08:23:03 | 显示全部楼层
楼主,我对那个32*8的例子很感兴趣,能否给出这个教程的链接,先谢谢了
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-6-16 16:06:11 | 显示全部楼层
糯米基 发表于 2013-6-16 08:23
楼主,我对那个32*8的例子很感兴趣,能否给出这个教程的链接,先谢谢了

不是已经有链接了吗。一开始就是了。
没关係,这里再放一次。
http://www.solderlab.de/index.ph ... modular-plasma-wall
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-6-16 16:17:54 | 显示全部楼层
糯米基 发表于 2013-6-16 08:23
楼主,我对那个32*8的例子很感兴趣,能否给出这个教程的链接,先谢谢了

除了32*8,在他们的网站里还有一个12*8 RGB矩阵
http://www.solderlab.de/index.php/led-projects/rgb-matrix-12x8
我已经改成8*8,且每粒LED更换成两尺的LED Strip。总共用了64条LED Strip,安置在墙上。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-6 21:27 , Processed in 0.053687 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表