User Tools

Site Tools


led_matrix_shades_bitmap_patterns

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
led_matrix_shades_bitmap_patterns [2014/07/29 14:34]
macegr
led_matrix_shades_bitmap_patterns [2014/07/29 16:18]
macegr
Line 1: Line 1:
 ====== Introduction ====== ====== Introduction ======
 The LED Matrix Shades use three main approaches to generating patterns on the front LED array: The LED Matrix Shades use three main approaches to generating patterns on the front LED array:
-  * Scroll a text message. A message string is mapped to a bitmap font, which is used to generate and scroll the bitmap representation of the text across the LED matrix. The topic is covered here: [[http://docs.macetech.com/doku.php/led_matrix_shades_changing_messages|Changing Messages]]+  * Scroll a text message. A message string is mapped to a bitmap font, which is used to generate and scroll the bitmap representation of the text across the LED matrix. The topic is covered here: [[led_matrix_shades_changing_messages|Changing Messages]]
   * Swap out full frame bitmap images. An array of bytes is stored in flash, retrieved, and the bits within each byte are mapped to the LED matrix. Swapping out several frames will allow animated images.   * Swap out full frame bitmap images. An array of bytes is stored in flash, retrieved, and the bits within each byte are mapped to the LED matrix. Swapping out several frames will allow animated images.
   * Generate patterns directly to the LED array using mathematical functions. Code can render a graphical pattern based on an incrementing counter, random input, etc.   * Generate patterns directly to the LED array using mathematical functions. Code can render a graphical pattern based on an incrementing counter, random input, etc.
  
 ====== Bitmap Frames ====== ====== Bitmap Frames ======
 +Before attempting to modify LED Matrix Shades code, you should go through the [[led_matrix_shades#programming_instructions|Programming Instructions]] to make sure that everything is set up correctly.
 +
 In the current implementation of the LED Matrix Shades code, bitmap frames are stored in flash memory as an array of bytes. They are stored in binary notation to make them a little easier to read and edit manually. The default AS1130Glasses sketch contains graphic frames associated with the ''beatingHearts()'' function, which cycles through three sizes of heart shapes to create a pulsing heart animation. The code for the bitmap frames is copied below: In the current implementation of the LED Matrix Shades code, bitmap frames are stored in flash memory as an array of bytes. They are stored in binary notation to make them a little easier to read and edit manually. The default AS1130Glasses sketch contains graphic frames associated with the ''beatingHearts()'' function, which cycles through three sizes of heart shapes to create a pulsing heart animation. The code for the bitmap frames is copied below:
 <code>// Full-frame bitmap graphics <code>// Full-frame bitmap graphics
Line 48: Line 50:
 }</code> }</code>
  
 +We'll go through the function and describe the meaning of each section.
 +<code>byte currentHeartFrame = 0;
 +byte heartLoopCount = 0;
 +void beatingHearts() {</code>
  
 +The two byte variables are global variables used to keep track of the current state of the animation (''currentHeartFrame''), and to count up a delay to slow the animation to the desired speed (''heartLoopCount''). The function is declared void with no parameters.
 +<code>  if (!patternInit) {
 +    switchDrawType(0,0);
 +    patternInit = true;
 +  }</code>
 +Most patterns require some type of startup task. The ''patternInit'' global variable is set to ''false'' whenever the pattern changes (either manually or automatically). In this case, the only required task is to run ''switchDrawType(0,0);'', which selects framebuffer 0, and disables PWM since this will be a bit frame rather than a PWM frame. Then ''patternInit'' is set to ''true'' so that this section of code will not be accessed the next time the function is called.
 +<code>  heartLoopCount++;
 +  if (heartLoopCount > 50) {
 +    heartLoopCount = 0;</code>
 +Every time the function is called, ''heartLoopCount'' is incremented. The rest of the code in the function will not be run until it reaches 50; this implements a delay between animated frames so that they display at the desired speed. Once the counter reaches 50, it is set back to 0 to start counting up again.
 +<code>    if (currentHeartFrame < 3) {
 +      loadGraphicsFrame(currentHeartFrame);
 +    } else {
 +      loadGraphicsFrame(5 - currentHeartFrame);
 +    }</code>
 +Since there are only three graphics frames for this pattern, the code needs to choose some frames in reverse order while the ''currentHeartFrame'' variable counts up. In this case, while the counter is 0, 1, or 2, that is the graphics frame to be loaded. If the counter is at 3, then 5 - 3 = 2 will be selected; when the counter is at 4, then 5 - 4 = 1 will be loaded.
 +<code>    currentHeartFrame++;
 +    if (currentHeartFrame > 5) currentHeartFrame = 0;
 +    
 +    writeBitFrame(0,0);
 +  }
 +}</code>
 +The ''currentHeartFrame'' variable will be incremented each time this portion of the function is run. The maximum value is 5, then the counter will be reset to 0. The end result is the following sequence of graphics frames loaded: ''0, 1, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0'' repeating indefinitely. Once the correct bitmap has been loaded, then the ''writeBitFrame(0,0)'' command will set frame 0 on the controller chips to the contents of buffer 0.
 +
 +The function above is designed to display an animation. If all you need is to display one frame, then the function can be much simpler:
 +<code>void displayFrameZero() {
 +  
 +  if (!patternInit) {
 +    switchDrawType(0,0);
 +    patternInit = true;
 +  }
 +  
 +  loadGraphicsFrame(0);
 +  writeBitFrame(0,0);
 +}</code>
/home/macetec/public_html/docs/data/pages/led_matrix_shades_bitmap_patterns.txt ยท Last modified: 2014/07/29 17:03 by macegr