by

Assembling and Programming the Alpha Clock Five (Blue Edition)

This weekend I put together the Alpha Clock Five (Blue Edition). Check it out here.

After the assembly was complete I decided it would be cool if the clock could scroll text across the LEDs rather than just displaying static looking words. This proved to be a fairly challenging task.

I tried a couple of implementations, one iterative, the other recursive… neither worked. In my serial monitor I could see the clock going through all the iterations of displaying the words, but in the end only the last letter ever actually made it onto the LED display.

Finally, I found that when the program is in its loop() there is a very specific order that the program must execute in order to update the display. If you try to deviate from that order you will get unexpected results and the 0ff-screen buffer will not be loaded when you want it to be.

SPOILER ALERT! If you continue reading you will learn too much.

This method is the bulk of the work that needed to be done to program the clock to scroll text. It takes a character array (known in higher level languages as a string) and then grabs 5 letters out of it according to the “wordStep” that it is given. It also adds blank space at the beginning and end so that the first letter of the word begins on the 5th LED. So, for example, the words “WELCOME TO THE JUNGLE” would print the sequence ”    W” first. Then ”   WE” and ”  WEL”

The whole thing would look like this:

W

WE

WEL

WELC

WELCO

ELCOM

LCOME

COME

OME T

ME TO

E TO

TO T

TO TH

O THE

THE

THE J

HE JU

E JUN

JUNG

JUNGL

UNGLE

NGLE

GLE

LE

E

The Code:

char wordOut[5];

void GetWordStep(char WordIn[], int length, int wordStep) {
    unsigned int wordSize = length;
    int tempWordSize = wordSize + 8;
    char tempWord[tempWordSize];

    for(int i = 0; i < tempWordSize; i++) {
        if(i < 4 || i >= wordSize+4) {
            tempWord[i] = ' ';
        } else {
            tempWord[i] = WordIn[i-4];
        }
    }

    wordOut[0] = tempWord[wordStep-1];
    wordOut[1] = tempWord[wordStep];
    wordOut[2] = tempWord[wordStep+1];
    wordOut[3] = tempWord[wordStep+2];
    wordOut[4] = tempWord[wordStep+3];
}

More Code:

I have a diffchecker set up to distribute this code to anyone who wants it. You can find it here. The major changes begin on line 755, and end on line number 797. If you copy and paste the revised code you will just modify your clock to scroll HELLO WORLD once as it is plugged in.

Write a Comment

Comment

Webmentions

  • Timed Reminders with Alpha Clock Five – deobfuscate

    […] the code that I wrote a few days ago I was able to update the firmware to scroll “STAGE CODE” on Thursdays, on even […]