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.

Project Help and Ideas » My first attempt at "modifying" a project.

January 02, 2010
by Phrank916
Phrank916's Avatar

So, I took the challenge at the bottom of page 65 in the NerdKit guide which reads:

If you feel up to it, modify the code to also write a message to the LCD. Perhaps just a simple “hello”, or even consider printing whether the LCD is on or off at that point in time.

Here is what I came up with:

#define F_CPU 14745600
#include <stdio.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <inttypes.h>
#include "../libnerdkits/delay.h"
#include "../libnerdkits/lcd.h"

// PIN DEFINITIONS:
//
// PC4 -- LED anode

int main() {
  // LED as output
  DDRC |= (1<<PC4);

  lcd_init();
  lcd_home();
  // print message to screen
  //             20 columns wide:
  //                     01234567890123456789
  lcd_line_one();
  lcd_write_string(PSTR("    This is the     "));
  lcd_line_two();
  lcd_write_string(PSTR("    LED Flashing    "));
  lcd_line_three();
  lcd_write_string(PSTR("Project with NerdKit"));

  // loop keeps looking forever
  while(1) {
    // turn on LED and write ON msg to LCD
    PORTC |= (1<<PC4);
    lcd_line_four();
    lcd_write_string(PSTR("       LED ON!!     "));

    //delay for 500 milliseconds to let the light stay on
    delay_ms(500);

    // turn off LED and write OFF msg to LCD
    PORTC &= ~(1<<PC4);
    lcd_line_four();
    lcd_write_string(PSTR("       LED OFF!!    "));

    //delay for 500 milliseconds to let the light stay off
    delay_ms(500);

  }

  return 0;
}

And it WORKED!! This has been so much fun actually comprehending this stuff, and now I'm starting to brainstorm on new things I want to eventually try. NerdKits are the coolest! I'm so glad my wife actually got me what I asked for this year instead of socks and ties, LOL! Thanks Mike and Humberto!

Ted

January 03, 2010
by Rick_S
Rick_S's Avatar

Welcome to the forums Ted!!

Glad to hear you have everything up and running well. If you do run into any problems though, don't be afraid to ask. There are lots of friendly people here to help out when needed.

Rick

Post a Reply

Please log in to post a reply.

Did you know that two resistors plus a transistor can be used to make a better voltage supply? Learn more...