2.1k
A couple of simple examples, we used an RGB LED breakout. This was a common anode type, so to switch an LED on you need to switch the appropriate port pin low.
Schematic
Code
These examples were written in mikroC PRO for AVR
Example 1 : Cycle through Red, green and blue colours
void main() { DDRB = 0xFF; // Set direction to be output do { PORTB = 0xFF; // Turn OFF diodes on PORTB Delay_ms(200); // 1 second delay PORTB = 0xFE; Delay_ms(200); // 1 second delay PORTB = 0xFD; Delay_ms(200); // 1 second delay PORTB = 0xFB; Delay_ms(100); // 1 second delay } while(1); // Endless loop }
Example 2 : Cycle through all colours
void main() { DDRB = 0xFF; PORTB = 0xFF; // Set RB0 to high 00000001 do // To set infinite loop { PORTB = PORTB - 0x01; // Delay_ms(250); if(PORTB == 0xF8) //11111000 = R,G,B on { PORTB = 0xFF; //LEDS off Delay_ms(500); } }while(1); // To set infinite loop }
Links
ATMEGA16/ATmega32 AVR Minimum System Board + USB ISP USBasp Programmer