Bargraph Scrolling (prepared for the 2019-2020 TEI3M ACES)

 

Apart from their arithmetic and logic applications, Arduino C's 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 weeks ahead.

A common animation technique used in many computer gaming 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 access to a (1D) 8-LED bargraph. One could interpret a 32-bit unsigned integer variable as consisting of 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. A uint32_t variable, buff, is first assigned the value of 0x000E0. (uint16_t would also work)
  2. Exploit the highByte() function that we recently encountered, to obtain the second least-significant byte of this 4-byte variable and present it on your display (the first time through leaves all 8 LEDs off as the byte value is 0)
  3. Apply the bit shift left operator, <<, which causes the most significant bit to move out of view and the least-significant bit filled with a 0 (indicated in red below) to move into view.
  4. After 16 shifts, the initial least-significant byte has cleared the display and you can reload value with 0x000E0.
  5. Return to Step 2.