新手試試 --- Arduino RGB Dot Matrix RGB 7+1色滾動圖案

單色圖案好似太簡單,試下搞個7+1色滾動圖案
都係用番E塊板
http://www.hkepc.com/forum/viewt ... mp%3Bascdesc%3DDESC

RGB Dot Matrix PCB
RGBMatrix_PCB_Front.jpg
2009-9-1 10:00
RGBMatrix_PCB_Rear.jpg
2009-9-1 10:00

搞時發覺,D灯位位置同個圖案倒轉要改pin接線位。
另外唔知係唔係銲得唔好,定係D接線太長,D信號用PORTD同PORTB時會出錯,
用番For loop就正常番,遲D再搞過,睇清係乜問題。

搵到大部份既原因可以加番delay解決。

張線路圖改左pin2-9咁接。

RGB Dot Matrix RGB 7+1色滾動圖案 Schematic Diagram
RGBMatrix_v2c.jpg
2009-9-1 10:04



ps: 解決左大部份用PORTD同PORTB時會出錯既問題,加番說明。

[ 本帖最後由 zonebaby 於 2009-9-5 09:33 編輯 ]

TOP

個code改左,分為RGB三路控制,利用三組RGB單色圖案重曡出7+1色的圖案。
  1. /*
  2.   1 x  8X8 RGB Matrix Common Cathode - Simple RGB 7+1 color pattern

  3.   Layout:
  4.    
  5.    Drive: HD74HC373P x4

  6.     gnd = OC Red, Green, Blue, Common
  7.    pin9 = 1D
  8.    pin8 = 2D
  9.    pin7 = 3D
  10.    pin6 = 4D
  11.    pin5 = 5D
  12.    pin4 = 6D
  13.    pin3 = 7D
  14.    pin2 = 8D
  15.   pin10 = En G Blue
  16.   pin11 = En G Green
  17.   pin12 = En G Red
  18.   pin13 = En G Common
  19.   
  20.    pin1 = Blink Loop Start LED
  21.   
  22. */
  23.   
  24.   const static byte PatternR[32] = {
  25.     B00000001,B11111100,
  26.     B00000010,B00000000,
  27.     B00000010,B00000000,
  28.     B00000010,B00111100,
  29.     B00000010,B00011100,
  30.     B00000010,B00011100,
  31.     B00000010,B00010100,
  32.     B00000010,B00011000,
  33.     B00000001,B11111100,
  34.     B00000010,B00000000,
  35.     B00000010,B00000000,
  36.     B00000010,B00111100,
  37.     B00000010,B00011100,
  38.     B00000010,B00011100,
  39.     B00000010,B00010100,
  40.     B00000010,B00011000,
  41.   };
  42.   const static byte PatternG[32] = {
  43.     B00000000,B00000000,
  44.     B00000001,B11111100,
  45.     B00000001,B00000000,
  46.     B00000001,B01111000,
  47.     B00000001,B01110000,
  48.     B00000001,B01100100,
  49.     B00000001,B01000100,
  50.     B00000001,B00011000,
  51.     B00000000,B00000000,
  52.     B00000001,B11111100,
  53.     B00000001,B00000000,
  54.     B00000001,B01111000,
  55.     B00000001,B01110000,
  56.     B00000001,B01100100,
  57.     B00000001,B01000100,
  58.     B00000001,B00011000,
  59.   };
  60.   const static byte PatternB[32] = {
  61.     B00000000,B00000000,
  62.     B00000000,B00000000,
  63.     B00000000,B11111100,
  64.     B00000000,B10000000,
  65.     B00000000,B11000000,
  66.     B00000000,B11111100,
  67.     B00000000,B11110100,
  68.     B00000000,B11111000,
  69.     B00000000,B00000000,
  70.     B00000000,B00000000,
  71.     B00000000,B11111100,
  72.     B00000000,B10000000,
  73.     B00000000,B11000000,
  74.     B00000000,B11111100,
  75.     B00000000,B11110100,
  76.     B00000000,B11111000,
  77.   };

  78. //  long randColor;
  79.   long ThedPattern;
  80.   int colorpin;
  81.   void setup()   {   

  82. //  Serial.begin(9600);
  83. //  randomSeed(analogRead(0));
  84.   
  85.   // initialize the digital pin as an output:
  86.   pinMode(1, OUTPUT);
  87.   DDRB = DDRB | B00111111;
  88.   DDRD = DDRD | B11111100;

  89.   // initialize the digital pin to switch off the RGB Matrix:

  90.   PORTB &= B11000011;
  91.   delay(1);
  92.   PORTD &= B00000011;
  93.   PORTB &= B11000000;
  94.   delay(1);
  95.   PORTB |= B00111100;  //switch on CRGB input
  96.   delay(1);
  97.   PORTB &= B11000000;  //switch off CRGB input
  98.   delay(10);
  99.   //test RGB
  100.   for (colorpin=12; colorpin >=10; colorpin--)
  101.   {
  102.     PORTD |= B11111100;
  103.     PORTB |= B00000011;
  104.     digitalWrite(colorpin,HIGH);  
  105.     delay(800);
  106.     PORTD &= B00000011;
  107.     PORTB &= B11111100;
  108.    digitalWrite(colorpin, HIGH);
  109.    digitalWrite(colorpin, LOW);
  110.     delay(200);
  111.   }
  112.   // switch off the display
  113.   PORTD |= B11111100;
  114.   PORTB |= B00000011;
  115.   digitalWrite(13,HIGH);
  116.   digitalWrite(13,LOW);   
  117.   
  118.   // blink Loop Start LED
  119.   for (int i=1; i <=5; i++)
  120.   {
  121.     digitalWrite(1, HIGH);
  122.     delay(100);
  123.     digitalWrite(1, LOW);
  124.     delay(100);
  125.   }
  126. }

  127. void loop()                     
  128. {
  129. int rowpattern;
  130. int timedelay = 100;

  131.   for (int runno=0; runno <=15; runno++)
  132.   {  
  133.   ThedPattern = 18+runno; // random(1,9);
  134. //  randColor = random(10,13);
  135.   for (int i=1; i <=256; i++)
  136.   {  
  137.   for (int zp=9; zp >=2; zp--)
  138.   {
  139.     rowpattern=ThedPattern-zp*2;
  140.     //row selection
  141.     PORTD |= B11111100;
  142.     PORTB |= B00000011;
  143.     digitalWrite(zp, LOW);
  144.     digitalWrite(13, HIGH);
  145.     digitalWrite(13, LOW);
  146.          for (int y=2; y <=9; y++)
  147.         {
  148.         digitalWrite(y, LOW);
  149.         }      
  150.     //row pattern
  151.     PORTD |= (B11111100 & PatternR[rowpattern+1]);
  152.     PORTB |= (B00000011 & PatternR[rowpattern]);
  153.     //set color
  154.     digitalWrite(12, HIGH);
  155.     delayMicroseconds(timedelay);
  156.     PORTD &= B00000011;
  157.     PORTB &= B11111100;
  158.     digitalWrite(12, LOW);
  159.     PORTD |= (B11111100 & PatternG[rowpattern+1]);
  160.     PORTB |= (B00000011 & PatternG[rowpattern]);
  161.     //set color
  162.     digitalWrite(11, HIGH);
  163.     delayMicroseconds(timedelay);
  164.     PORTD &= B00000011;
  165.     PORTB &= B11111100;
  166.     digitalWrite(11, LOW);
  167.     PORTD |= (B11111100 & PatternB[rowpattern+1]);
  168.     PORTB |= (B00000011 & PatternB[rowpattern]);
  169.     digitalWrite(10, HIGH);
  170.     delayMicroseconds(timedelay);
  171.     PORTD &= B00000011;
  172.     PORTB &= B11111100;
  173.     digitalWrite(10, LOW);

  174.   }
  175.   }
  176.   }
  177. }
複製代碼
ps: 修正番用PORTD同PORTB時會出錯既問題,加了delay解決。

[ 本帖最後由 zonebaby 於 2009-9-5 09:27 編輯 ]

TOP

E個Code都係放在examples入面....

RGB Dot Matrix RGB Pattern Location

當Compile同upload成功後,再等一陣,個RGB Dot Matrix就會先開始測試RGB,然後熄哂佢。
跟住就顯示個圖案,並開始一行一行向上移,然後不斷重覆,....。

RGB Dot Matrix RGB Pattern Success
RGBMatrix_8color.jpg
2009-9-1 10:04


RGB Dot Matrix RGB Pattern 試機成功...

TOP

後記1:
執下個code方便入圖案,並搞過向上移動箭頭試下。
  1. /*
  2.   1 x  8X8 RGB Matrix Common Cathode - Simple Blink W/O PWM

  3.   Layout:
  4.    
  5.    Drive: HD74HC373P x4

  6.     gnd = OC Red, Green, Blue, Common
  7.    pin9 = 1D
  8.    pin8 = 2D
  9.    pin7 = 3D
  10.    pin6 = 4D
  11.    pin5 = 5D
  12.    pin4 = 6D
  13.    pin3 = 7D
  14.    pin2 = 8D
  15.   pin10 = En G Blue
  16.   pin11 = En G Green
  17.   pin12 = En G Red
  18.   pin13 = En G Common
  19.   
  20.    pin1 = Blink Loop Start LED
  21.    
  22.    color combination= 0 R RG RGB RB G GB B
  23.    
  24.    B G R
  25.    0 0 0   0
  26.    0 0 1   1   R
  27.    0 1 0   2   G
  28.    0 1 1   3   RG  Y
  29.    1 0 0   4   B
  30.    1 0 1   5   RB  P
  31.    1 1 0   6   GB  S
  32.    1 1 1   7   RGB W
  33.   
  34. */  
  35.    
  36. //    char Pattern1[]={'O'  ,'R'  ,'R'  ,'R'  ,'R'  ,'R'  ,'R'  ,'R'  };
  37. //    char Pattern2[]={'R'  ,'G'  ,'G'  ,'G'  ,'G'  ,'G'  ,'G'  ,'G'  };
  38. //    char Pattern3[]={'R'  ,'G'  ,'B'  ,'B'  ,'B'  ,'B'  ,'B'  ,'B'  };
  39. //    char Pattern4[]={'R'  ,'G'  ,'B'  ,'G'  ,'Y'  ,'Y'  ,'Y'  ,'R'  };
  40. //    char Pattern5[]={'R'  ,'G'  ,'B'  ,'S'  ,'G'  ,'Y'  ,'R'  ,'R'  };
  41. //    char Pattern6[]={'R'  ,'G'  ,'B'  ,'S'  ,'S'  ,'P'  ,'P'  ,'W'  };
  42. //    char Pattern7[]={'R'  ,'G'  ,'B'  ,'S'  ,'B'  ,'P'  ,'O'  ,'W'  };
  43. //    char Pattern8[]={'R'  ,'G'  ,'B'  ,'B'  ,'B'  ,'W'  ,'W'  ,'O'  };

  44.     char Pattern1[]={'O'  ,'O'  ,'O'  ,'R'  ,'R'  ,'O'  ,'O'  ,'O'  };
  45.     char Pattern2[]={'O'  ,'O'  ,'G'  ,'G'  ,'G'  ,'G'  ,'O'  ,'O'  };
  46.     char Pattern3[]={'O'  ,'B'  ,'B'  ,'B'  ,'B'  ,'B'  ,'B'  ,'O'  };
  47.     char Pattern4[]={'O'  ,'O'  ,'Y'  ,'Y'  ,'Y'  ,'Y'  ,'O'  ,'O'  };
  48.     char Pattern5[]={'O'  ,'O'  ,'P'  ,'P'  ,'P'  ,'P'  ,'O'  ,'O'  };
  49.     char Pattern6[]={'O'  ,'O'  ,'S'  ,'S'  ,'S'  ,'S'  ,'O'  ,'O'  };
  50.     char Pattern7[]={'O'  ,'O'  ,'W'  ,'W'  ,'W'  ,'W'  ,'O'  ,'O'  };
  51.     char Pattern8[]={'O'  ,'O'  ,'O'  ,'O'  ,'O'  ,'O'  ,'O'  ,'O'  };
  52.    
  53.     char* Pattern[]={Pattern1,Pattern2,Pattern3,Pattern4,Pattern5,Pattern6,Pattern7,Pattern8};

  54.   int datapin;
  55.   int colorpin;
  56.   int patternww;
  57.   byte PatternRH[32];
  58.   byte PatternGH[32];
  59.   byte PatternBH[32];
  60.   byte PatternRL[32];
  61.   byte PatternGL[32];
  62.   byte PatternBL[32];
  63.   void setup()   {


  64.   
  65.   for (int i=0; i <=7; i++)
  66.     {
  67.       for (int j=0; j <=1; j++)
  68.         {
  69.             bitWrite(PatternRH[i],(1-j),(Pattern[i][j] == 'R'|(Pattern[i][j] == 'Y')|(Pattern[i][j] == 'P')|(Pattern[i][j] == 'W')));
  70.             bitWrite(PatternGH[i],(1-j),(Pattern[i][j] == 'G'|(Pattern[i][j] == 'Y')|(Pattern[i][j] == 'S')|(Pattern[i][j] == 'W')));
  71.             bitWrite(PatternBH[i],(1-j),(Pattern[i][j] == 'B'|(Pattern[i][j] == 'P')|(Pattern[i][j] == 'S')|(Pattern[i][j] == 'W')));
  72.         }
  73.       for (int j=2; j <=7; j++)
  74.         {
  75.             bitWrite(PatternRL[i],(9-j),(Pattern[i][j] == 'R'|(Pattern[i][j] == 'Y')|(Pattern[i][j] == 'P')|(Pattern[i][j] == 'W')));
  76.             bitWrite(PatternGL[i],(9-j),(Pattern[i][j] == 'G'|(Pattern[i][j] == 'Y')|(Pattern[i][j] == 'S')|(Pattern[i][j] == 'W')));
  77.             bitWrite(PatternBL[i],(9-j),(Pattern[i][j] == 'B'|(Pattern[i][j] == 'P')|(Pattern[i][j] == 'S')|(Pattern[i][j] == 'W')));
  78.         }
  79.     }      
  80.   // initialize the digital pin as an output:
  81.   pinMode(1, OUTPUT);
  82.   DDRB = DDRB | B00111111;
  83.   DDRD = DDRD | B11111100;

  84.   // initialize the digital pin to switch off the RGB Matrix:

  85.   PORTB &= B11000011;
  86.   delay(1);
  87.   PORTD &= B00000011;
  88.   PORTB &= B11000000;
  89.   delay(1);
  90.   PORTB |= B00111100;  //switch on CRGB input
  91.   delay(1);
  92.   PORTB &= B11000000;  //switch off CRGB input
  93.   delay(10);
  94.   //test RGB
  95.   for (colorpin=12; colorpin >=10; colorpin--)
  96.   {
  97.     PORTD |= B11111100;
  98.     PORTB |= B00000011;
  99.     digitalWrite(colorpin,HIGH);  
  100.     delay(800);
  101.     PORTD &= B00000011;
  102.     PORTB &= B11111100;
  103.    digitalWrite(colorpin, HIGH);
  104.    digitalWrite(colorpin, LOW);
  105.     delay(200);
  106.   }
  107.   // switch off the display
  108.   PORTD |= B11111100;
  109.   PORTB |= B00000011;
  110.   digitalWrite(13,HIGH);
  111.   digitalWrite(13,LOW);   
  112.   // blink Loop Start LED
  113.   for (int i=1; i <=5; i++)
  114.   {
  115.     digitalWrite(1, HIGH);
  116.     delay(100);
  117.     digitalWrite(1, LOW);
  118.     delay(100);
  119.   }
  120. }

  121. void loop()                     
  122. {
  123.   int patternlen = 8;
  124.   int timedelay = 8;
  125. int datapin[]={9, 8, 7, 6, 5, 4, 3, 2};
  126.   for (int runno=0; runno <=patternlen-1; runno++)
  127.   {  
  128.   for (int i=1; i <=256; i++)
  129.   {  
  130.   for (int zp=0; zp <=7; zp++)
  131.   {
  132.     PORTD |= B11111100;
  133.     PORTB |= B00000011;
  134.     digitalWrite(datapin[zp], LOW);
  135.     digitalWrite(13, HIGH);
  136.     digitalWrite(13, LOW);
  137.          for (int y=2; y <=9; y++)
  138.         {
  139.         digitalWrite(y, LOW);
  140.         }
  141.         patternww = zp+runno;
  142.         if (patternww > (patternlen-1))
  143.         {
  144.                 patternww=patternww-8;
  145.         }
  146.     //row pattern
  147.     PORTD |= (B11111100 & PatternRL[patternww]);
  148.     PORTB |= (B00000011 & PatternRH[patternww]);
  149.     //set color
  150.     digitalWrite(12, HIGH);
  151.     delayMicroseconds(timedelay);
  152.     PORTD &= B00000011;
  153.     PORTB &= B11111100;
  154.     digitalWrite(12, LOW);
  155.     PORTD |= (B11111100 & PatternGL[patternww]);
  156.     PORTB |= (B00000011 & PatternGH[patternww]);
  157.     digitalWrite(11, HIGH);
  158.     delayMicroseconds(timedelay);
  159.     PORTD &= B00000011;
  160.     PORTB &= B11111100;
  161.     digitalWrite(11, LOW);
  162.     PORTD |= (B11111100 & PatternBL[patternww]);
  163.     PORTB |= (B00000011 & PatternBH[patternww]);
  164.     digitalWrite(10, HIGH);
  165.     delayMicroseconds(timedelay);
  166.     PORTD &= B00000011;
  167.     PORTB &= B11111100;
  168.     digitalWrite(10, LOW);
  169.   }
  170.   }
  171.   }
  172. }
複製代碼
ps: 修正番大部份用PORTD同PORTB時會出錯既問題,加了delay解決。

[ 本帖最後由 zonebaby 於 2009-9-5 09:39 編輯 ]

TOP

後記2
E個Code都係放在examples入面....

RGB Dot Matrix RGB Pattern Location

當Compile同upload成功後,再等一陣,個RGB Dot Matrix就會先開始測試RGB,然後熄哂佢。
跟住就顯示個向上箭頭圖案,並開始一行一行向上移動,然後不斷重覆,....。

RGB Dot Matrix RGB Pattern Success
RGBMatrix Arrow Success.jpg
2009-9-3 00:56
RollingArrow.gif
2009-9-5 12:35


RGB Dot Matrix RGB Pattern 試機成功..:

ps: 加多張rolling arrow圖

[ 本帖最後由 zonebaby 於 2009-9-5 12:35 編輯 ]

TOP

修正番大部份用PORTD同PORTB時會出錯既問題,加左delay解決,
效果好D。其它就遲D再搞過,睇清係乜問題。

TOP