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 » LCD sequence question

July 14, 2010
by ZachT
ZachT's Avatar

First I'd like to say I just got my kit and I'm having a blast. I got to the point where I uploaded my first program and I've edited it a bit. I got the third line to blink! It only took me an hour and a half to figure out the code. I suppose no one is an expert over night.

Anyway, I have 20 characters to work with. I want a * to start in the middle and then it to fill up all 20 spaces with *** ect and then repeat that. I'm not sure where to begin putting this into code. Can someone point me in the right direction?

July 15, 2010
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Zach,

I am glad you are having fun with the NerdKit. Let's see if I can get you going in the right direction with your idea. Take a look at the following code:

// LED as output
lcd_init();
FILE lcd_stream = FDEV_SETUP_STREAM(lcd_putchar, 0, _FDEV_SETUP_WRITE);
lcd_home();

uint8_t i;
while(1){
  lcd_clear_and_home();
  lcd_line_one();
  for(i=0;i<20;i++){
    lcd_write_string(PSTR("*"));
    delay_ms(20);
  }
}

If you put this in your main function, the top line will fill in with stars starting from the beginning. I used a simple for loop that writes a single * to the screen every time. Modifying this idea to fill the stars in from the middle will require some thinking. Give it a shot and let us know what you come up with.

Humberto

Post a Reply

Please log in to post a reply.

Did you know that spinning a permanent magnet motor makes a voltage? Learn more...