User Tools

Site Tools



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
Next revision Both sides next revision
led_matrix_shades_bitmap_patterns [2014/07/29 14:34]
led_matrix_shades_bitmap_patterns [2014/07/29 14:57]
Line 48: Line 48:
 }</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);
 +  }
 +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);
/home/macetec/public_html/docs/data/pages/led_matrix_shades_bitmap_patterns.txt ยท Last modified: 2014/07/29 17:03 by macegr