Created
September 19, 2010 23:11
-
-
Save rtanglao/587207 to your computer and use it in GitHub Desktop.
blink 3 leds attached to the nerd kit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // led_blink.c | |
| // for NerdKits with ATmega168 | |
| // [email protected] | |
| #define F_CPU 14745600 | |
| #include <avr/io.h> | |
| #include <avr/interrupt.h> | |
| #include <avr/pgmspace.h> | |
| #include <inttypes.h> | |
| #include "../libnerdkits/delay.h" | |
| #include "../libnerdkits/lcd.h" | |
| #include <math.h> | |
| // PIN DEFINITIONS: | |
| // | |
| // PC4 -- LED anode | |
| int main() { | |
| lcd_init(); | |
| FILE lcd_stream = FDEV_SETUP_STREAM(lcd_putchar, 0, _FDEV_SETUP_WRITE); | |
| lcd_home(); | |
| lcd_write_string(PSTR("Hello LED!")); | |
| // LED as output | |
| DDRC |= (1<<PC4); // green LED | |
| DDRC |= (1<<PC5); // red LED | |
| DDRC |= (1<<PC3); // yellow LED | |
| // turn on LEDs | |
| PORTC |= (1<<PC4); | |
| PORTC |= (1<<PC5); | |
| PORTC |= (1<<PC3); | |
| // loop keeps looking forever | |
| int i; | |
| for (i=1;i>=0;i++,delay_ms(300)) { | |
| lcd_clear_and_home(); | |
| lcd_write_string(PSTR("Hello LED!")); | |
| lcd_line_two(); | |
| if (i % 3 == 0) { | |
| lcd_write_string(PSTR("Toggle yellow")); | |
| PORTC ^= (1<<PC3); | |
| } | |
| else if (i % 2 == 0) { | |
| lcd_write_string(PSTR("Toggle red ")); | |
| PORTC ^= (1<<PC5); | |
| } | |
| else if (i % 1 == 0) { | |
| lcd_write_string(PSTR("Toggle green ")); | |
| PORTC ^= (1<<PC4); | |
| } | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment