﻿{"id":538,"date":"2019-07-07T00:49:26","date_gmt":"2019-07-06T21:49:26","guid":{"rendered":"http:\/\/allchina.a-lisa.org\/?p=538"},"modified":"2019-07-08T17:28:06","modified_gmt":"2019-07-08T14:28:06","slug":"7-july-2019-0049","status":"publish","type":"post","link":"https:\/\/allchina.a-lisa.org\/?p=538","title":{"rendered":"RGB \u043f\u0430\u043d\u0435\u043b\u0438"},"content":{"rendered":"<h1>Test Example Code<\/h1>\n<p>by <a href=\"https:\/\/learn.adafruit.com\/users\/pburgess\">Phillip Burgess<\/a><\/p>\n<p>We have example code ready to go for these displays. It&#8217;s compatible with the Arduino Uno or Mega\u2026but <em><strong>not<\/strong><\/em> other boards like the Leonardo, nor \u201cArduino-like\u201d boards such as Netduino\u2026programming gurus <em>might<\/em> be able to port it to other microcontrollers by adapting the C++ source, but as written it does some pretty low-level, non-portable things.<\/p>\n<p><!--more--><\/p>\n<p>The library works with a LIMITED NUMBER of boards: Arduino Uno, Mega, Zero, Adafruit Metro M0 and Metro M4. Other boards (such as the Arduino Leonardo) ARE NOT SUPPORTED.<\/p>\n<p><em>Two<\/em> libraries need to be downloaded and installed: first is the <a href=\"https:\/\/github.com\/adafruit\/RGB-matrix-Panel\">RGB Matrix Panel library<\/a> (this contains the low-level code specific to this device), and second is the <a href=\"https:\/\/github.com\/adafruit\/Adafruit-GFX-Library\">Adafruit GFX Library<\/a> (which handles graphics operations common to many displays we carry).<\/p>\n<table>\n<tbody>\n<tr>\n<td>\n<ul>\n<li><a href=\"https:\/\/learn.adafruit.com\/assets\/56430\"><img decoding=\"async\" src=\"https:\/\/cdn-learn.adafruit.com\/assets\/assets\/000\/056\/430\/medium640\/led_matrices_lib-gfx.png?1530127536\" alt=\"led_matrices_lib-gfx.png\" \/><\/a><\/li>\n<li><a href=\"https:\/\/learn.adafruit.com\/assets\/56430\"><img decoding=\"async\" src=\"https:\/\/cdn-learn.adafruit.com\/assets\/assets\/000\/056\/430\/thumb160\/led_matrices_lib-gfx.png?1530127536\" alt=\"led_matrices_lib-gfx.png\" \/><\/a><\/li>\n<li><a href=\"https:\/\/learn.adafruit.com\/assets\/56431\"><img decoding=\"async\" src=\"https:\/\/cdn-learn.adafruit.com\/assets\/assets\/000\/056\/431\/thumb160\/led_matrices_lib-matrix.png?1530127547\" alt=\"led_matrices_lib-matrix.png\" \/><\/a><\/li>\n<\/ul>\n<\/td>\n<td>Both libraries can be found and installed using the Arduino Library Manager (<strong>Sketch\u2192Include Library\u2192Manage Libraries\u2026<\/strong>). Search for \u201cgfx\u201d and \u201crgb matrix panel\u201d and install the corresponding Adafruit libraries.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Now you are ready to test! Open up the IDE and load <strong>File\u2192Examples\u2192RGBmatrixPanel\u2192testcolors_16x32<\/strong> (for the 16&#215;32 panel) or <strong>File\u2192Examples\u2192RGBmatrixPanel\u2192colorwheel_32x32<\/strong> (for the 32&#215;32 panel).<\/p>\n<p><strong>If using an Arduino Mega 2560,<\/strong> in addition to wiring changes previously mentioned, you&#8217;ll need to make a small change to each of the example sketches. This line:<\/p>\n<p>Download: <a href=\"https:\/\/learn.adafruit.com\/pages\/904\/elements\/1191774\/download\">file<\/a><\/p>\n<p><a href=\"https:\/\/learn.adafruit.com\/32x16-32x32-rgb-led-matrix\/test-example-code#\">Copy Code<\/a><\/p>\n<ol>\n<li>#define CLK 8 \/\/ MUST be on PORTB! (Use pin 11 on Mega)<\/li>\n<\/ol>\n<p>Should be changed to:<br \/>\nDownload: <a href=\"https:\/\/learn.adafruit.com\/pages\/904\/elements\/1191776\/download\">file<\/a><\/p>\n<p><a href=\"https:\/\/learn.adafruit.com\/32x16-32x32-rgb-led-matrix\/test-example-code#\">Copy Code<\/a><\/p>\n<ol>\n<li>#define CLK 11<\/li>\n<\/ol>\n<p><em>(Any of digital pins 10-13 and 50-53 can be used for this function on the Mega, with the corresponding wiring change. The examples all reference pin 11.)<\/em><\/p>\n<p>If using an <strong>Adafruit Metro M4<\/strong> (<em>not<\/em> M0 or 328), the CLK change would instead be:<\/p>\n<p>Download: <a href=\"https:\/\/learn.adafruit.com\/pages\/904\/elements\/2992741\/download\">file<\/a><\/p>\n<p><a href=\"https:\/\/learn.adafruit.com\/32x16-32x32-rgb-led-matrix\/test-example-code#\">Copy Code<\/a><\/p>\n<ol>\n<li>#define CLK A4<\/li>\n<\/ol>\n<p>After uploading, with the 16&#215;32 panel you should see the following:<br \/>\n<a href=\"https:\/\/learn.adafruit.com\/assets\/2959\"><img decoding=\"async\" src=\"https:\/\/cdn-learn.adafruit.com\/assets\/assets\/000\/002\/959\/medium800\/led_matrix_allcolors.jpg?1396789390\" alt=\"led_matrix_allcolors.jpg\" \/><\/a><br \/>\nThis is a test pattern that shows 512 colors (out of 4096) on the 512 pixels. Since there&#8217;s no really elegant way to show a 3-dimensional color space (R\/G\/B) in two dimensions, there&#8217;s just repeating grids of red\/green with increasing blue. Anyways, this shows you the range of colors you can achieve!<\/p>\n<p>or, with the 32&#215;32 panel:<br \/>\n<a href=\"https:\/\/learn.adafruit.com\/assets\/2960\"><img decoding=\"async\" src=\"https:\/\/cdn-learn.adafruit.com\/assets\/assets\/000\/002\/960\/medium800\/led_matrix_rgbmatrix3232wheel_lrg.jpg?1396789401\" alt=\"led_matrix_rgbmatrix3232wheel_lrg.jpg\" \/><\/a><br \/>\nNow that you&#8217;ve got it working here are a few things to look for:<\/p>\n<p>The most useful line to look at is:<br \/>\nDownload: <a href=\"https:\/\/learn.adafruit.com\/pages\/904\/elements\/1191783\/download\">file<\/a><\/p>\n<p><a href=\"https:\/\/learn.adafruit.com\/32x16-32x32-rgb-led-matrix\/test-example-code#\">Copy Code<\/a><\/p>\n<ol>\n<li>matrix.drawPixel(x, y, matrix.Color333(r, g, b));<\/li>\n<\/ol>\n<p>which is where we actually draw to the display. This code only draws one pixel at a time. The <strong>x<\/strong> and<strong> y<\/strong>coordinates are the individual pixels of the display. <strong>(0,0)<\/strong> is in the top left corner, <strong>(31, 15)<\/strong> is in the bottom right (remember that we start counting at 0 here!). To create a color, you will want to use the helper funciton <strong>Color333<\/strong> which will take three 3-bit numbers and combine them into a single packed integer. So for example, the first argument, <strong>r<\/strong> can range from 0 to 7. Likewise for <strong>g<\/strong>and <strong>b<\/strong>. To make a pixel that is pure red, <strong>r<\/strong> would be 7 and <strong>g, b<\/strong> would be 0. To make a white pixel, set all to 7. To make a black (off) pixel, set the colors to 0. A similar function, <strong>Color444<\/strong>, accepts three 4-bit numbers for up to 4096 colors.<\/p>\n<p>Now we can open up the next example, which shows the rest of the library capabilities.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Test Example Code by Phillip Burgess We have example code ready to go for these displays. It&#8217;s compatible with the<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[98],"tags":[],"class_list":["post-538","post","type-post","status-publish","format-standard","hentry","category-arduino"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p7OYvE-8G","_links":{"self":[{"href":"https:\/\/allchina.a-lisa.org\/index.php?rest_route=\/wp\/v2\/posts\/538","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/allchina.a-lisa.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/allchina.a-lisa.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/allchina.a-lisa.org\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/allchina.a-lisa.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=538"}],"version-history":[{"count":1,"href":"https:\/\/allchina.a-lisa.org\/index.php?rest_route=\/wp\/v2\/posts\/538\/revisions"}],"predecessor-version":[{"id":541,"href":"https:\/\/allchina.a-lisa.org\/index.php?rest_route=\/wp\/v2\/posts\/538\/revisions\/541"}],"wp:attachment":[{"href":"https:\/\/allchina.a-lisa.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=538"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/allchina.a-lisa.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=538"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/allchina.a-lisa.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=538"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}