NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Something very odd with the LED array code

June 07, 2014
by lailai
lailai's Avatar

I'd like to scroll a predefined message on my LED array. However, something very odd is happening - if I add the code to increment the character offset, the LED array gets broken BEFORE the code is actually executed!

Here is my code (note the commented out line):

void do_scrolling_display() {
  int8_t offset = COLS - 1, next_offset = offset;
  uint8_t characterOffset = 0;
  char *message = "HELLO WORLD ";

  while(1) {

    font_display(message[characterOffset], offset);
    next_offset = offset + font_width(message[characterOffset])+1;

    if(next_offset == COLS){

        //characterOffset++; <--- this line is the issue
        offset = next_offset;

        if(characterOffset == sizeof(message) / sizeof(char)){
            characterOffset = 0;



If I comment that line out, my LED array scrolls like:

'H H H H H '.. (expected)

If I do not comment the line:

'? ? ? ? ? '..

What is odd is that the first character becomes '?' even before the characterOffset++ has the chance to execute. I've tested that by placing a delay_ms(80000) before characterOffset++ is executed, and somehow it still screws up the first character despite never being executed ?!?

June 08, 2014
by Rick_S
Rick_S's Avatar

Many years ago, I heavily modified the NK code to give it much more flexibility for stored strings. While that writeup may still be available here, you can find it and the modified code on my website at

The test pattern function in my version of the program is all you need to modify to include the strings / characters you want to display.


June 08, 2014
by lailai
lailai's Avatar

Hi Rick,

Thanks for sharing that code! I am still interested learning what is wrong with my current code though, for learning purposes.

June 10, 2014
by lailai
lailai's Avatar

Any ideas? I'd really like to know what's happening here. I stripped the code to it's core and tested with gcc and it works as expected..

June 10, 2014
by lailai
lailai's Avatar


printf("%u", characterOffset); gives empty spaces in the serial connection.. Even though on the first run, it should be 0. I thought it may be running out of stack/heap (not sure correct term), but that doesn't seem to be the case..

Post a Reply

Please log in to post a reply.

Did you know that you can aim and fire a servo-controlled water gun from your computer? Learn more...