RSGC ACES: Bargraph Scrolling

 

Apart from their arithmetic and logic applications, bit shift operators (<< and >>) can be used to affect interesting animation sequences. In this lesson we'll introduce one such technique (in 1D). We'll extend the concept to 2D matrices later in the course.

A common animation technique used in many computer games, message boards, and recreational activities is to have multiple video buffers (memory) available, only one of which is visible to the viewer at a time. The hidden or back video buffer(s) are typically loaded with graphic content, out-of-sight of the viewer (to avoid flickering and other instabilities) only to be moved into view when fully updated with the next frame's worth of material. The user is obviously unaware that this 'page-flipping' technique is happening and the transitions go unnoticed. We can undertake a crude 1D simulation of this visible/hidden buffering technique using the concepts we have recently explored.

The Morland Bargraph V3 offers us indirect access to a (1D) 8-LED bargraph through the 74HC595 shift register. One could interpret a 16- or 32-bit unsigned integer variable as consisting of 2 or 4 separate bytes (buffers) of data. Study the animated gif below to depict the process. Now, using the code shell , undertake the following sequence of steps,

  1. The data to be animated is referred to as the sprite. Let's assume we wish to animate the uint8_t sprite with a value of 0xE0.
  2. A uint32_t variable, buff, is first assigned the value of sprite(0xE0). This buffer is large enough to be used with a 20-LED bargraph. A uint16_t type for buff, assigned a value of sprite (0xE0), would also work in our case since the MBv3 has only 1 visible byte buffer (bargraph).
  3. Exploit the highByte() function (or do your own shifting/masking) to obtain the SECOND least-significant byte of this variable and present it on your display (the first time through leaves all 8 visible LEDs off as the byte value is 0).
  4. Apply some short delay.
  5. Apply the bit shift left operator, <<, to buff
  6. Return to Step 3 (causing the most significant bit of the visible display to move out of view and the least-significant bit filled with a 1 to move into view)
  7. After 16 shifts, the initial least-significant bit of sprite has cleared the visible display and you can reload buff with sprite.
  8. Return to Step 2.