Modifications

Sauter à la navigation Sauter à la recherche
4 687 octets ajoutés ,  2 mars 2014 à 14:59
aucun résumé de modification
Ligne 1 : Ligne 1 :  
{{NeoPixel-UserGuide-NAV}}
 
{{NeoPixel-UserGuide-NAV}}
    +
== Introduction ==
 
{{ADFImage|NeoPixel-UserGuide-NeoMatrix-01.jpg|640px}}
 
{{ADFImage|NeoPixel-UserGuide-NeoMatrix-01.jpg|640px}}
   Ligne 22 : Ligne 23 :  
     #endif</nowiki>
 
     #endif</nowiki>
 
The extra ifdef/define/endif lines are only needed if you’re using an Arduino Due. Otherwise they can be left out.  
 
The extra ifdef/define/endif lines are only needed if you’re using an Arduino Due. Otherwise they can be left out.  
 +
 +
== Les layouts (disposition) ==
 +
Adafruit_NeoMatrix uses exactly the same coordinate system, color functions and graphics commands as the Adafruit_GFX library. If you’re new to the latter, [[Tutoriel Librairie Adafruit GFX|a separate tutorial explains its use]]. There are also example sketches included with the Adafruit_NeoMatrix library.
 +
 +
We’ll just focus on the constructor here — how to declare a two-dimensional display made from NeoPixels. Powering the beast is another matter, covered on the prior page.
 +
The library handles both single matrices — all NeoPixels in a single uniform grid — and tiled matrices — multiple grids combined into a larger display:
 +
 +
The library handles both single matrices — all NeoPixels in a single uniform grid — and tiled matrices — multiple grids combined into a larger display:
 +
 +
{{ADFImage|NeoPixel-UserGuide-NeoMatrix-10.png|640px}}
 +
 +
Let’s begin with the declaration for a single matrix, because it’s simpler to explain. We’ll be demonstrating the NeoPixel Shield for Arduino in this case — an 8x5 matrix of NeoPixels. When looking at this shield with the text in a readable orientation, the first pixel, #0, is at the top left. Each successive pixel is right one position — pixel 1 is directly to the right of pixel 0, and so forth. At the end of each row, the next pixel is at the left side of the next row. This isn’t something we decide in code…it’s how the NeoPixels are hard-wired in the circuit board comprising the shield.
 +
 +
{{ADFImage|NeoPixel-UserGuide-NeoMatrix-11.jpg|640px}}
 +
 +
We refer to this layout as row major and progressive. Row major means the pixels are arranged in horizontal lines (the opposite, in vertical lines, is column major). Progressive means each row proceeds in the same direction. Some matrices will reverse direction on each row, as it can be easier to wire that way. We call that a ''zigzag'' layout.
 +
 +
However…for this example, we want to use the shield in the “tall” direction, so the Arduino is standing up on the desk with the USB cable at the top. When we turn the board this way, the matrix layout changes…
 +
 +
{{ADFImage|NeoPixel-UserGuide-NeoMatrix-12.jpg|640px}}
 +
 +
Now the first pixel is at the '''top right'''. Pixels increment top-to-bottom — it’s now '''column major'''. The order of the columns is still '''progressive''' though.
 +
 +
We declare the matrix thusly:
 +
 +
<nowiki>    Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(5, 8, 6,
 +
    NEO_MATRIX_TOP + NEO_MATRIX_RIGHT +
 +
    NEO_MATRIX_COLUMNS + NEO_MATRIX_PROGRESSIVE,
 +
    NEO_GRB + NEO_KHZ800);</nowiki>
 +
 +
The first two arguments — 5 and 8 — are the width and height of the matrix, in pixels. The third argument — 6 — is the pin number to which the NeoPixels are connected. On the shield this is hard-wired to digital pin 6, but standalone matrices are free to use other pins.
 +
 +
The next argument is the interesting one. This indicates where the first pixel in the matrix is positioned and the arrangement of rows or columns. The first pixel {{underline|must}} be at one of the four corners; which corner is indicated by adding either NEO_MATRIX_TOP or NEO_MATRIX_BOTTOM to either NEO_MATRIX_LEFT or NEO_MATRIX_RIGHT. The row/column arrangement is indicated by further adding either NEO_MATRIX_COLUMNS or NEO_MATRIX_ROWS to either NEO_MATRIX_PROGRESSIVE or NEO_MATRIX_ZIGZAG. These values are all added to form a single value as in the above code.
 +
 +
NEO_MATRIX_TOP + NEO_MATRIX_RIGHT + NEO_MATRIX_COLUMNS + NEO_MATRIX_PROGRESSIVE
 +
 +
The last argument is exactly the same as with the NeoPixel library, indicating the type of LED pixels being used. In the majority of cases with the latest NeoPixel products, you can simply leave this argument off…the example code is just being extra descriptive.
 +
 +
'''The point of this setup is that the rest of the sketch never needs to think about the layout of the matrix. Coordinate (0,0) for drawing graphics will always be at the top-left, regardless of the actual position of the first NeoPixel.'''
 +
 +
===  Why not just use the rotation feature in Adafruit_GFX? ===
 +
Adafruit_GFX only handles rotation. Though it would handle our example above, it doesn’t cover every permutation of rotation and mirroring that may occur with certain matrix layouts, not to mention the zig-zag capability, or this next bit…
 +
 +
== Tiled Matrices ==
 +
A ''tiled'' matrix is comprised of multiple smaller NeoPixel matrices. This is sometimes easier for assembly or for distributing power. All of the sub-matrices need to be the same size, and must be ordered in a predictable manner. The Adafruit_NeoMatrix() constructor then receives some additional arguments:
    
{{NeoPixel-UserGuide-TRAILER}}
 
{{NeoPixel-UserGuide-TRAILER}}
29 917

modifications

Menu de navigation