Software

The code for the fading LED is written in C with the WINAVR C-Compiler. The code runs on a clock source of 16Mhz. You can copy and paste the text file into the WINAVR C-compiler.

// program name: mood lamp
// date: 16-03-2016
// target device: ATMeg8
// purpose: mix RGB LED to 8 colors with potmeter, uses ADC channel 0 input.
// author: www.avrprojects.net
//

#include <avr/io.h>
#include <util/delay.h>

#define F_CPU 16000000UL
#define LEDs PORTB
#define black 0b00000000
#define green 0b00000001
#define blue 0b00000010
#define cyan 0b00000011
#define red 0b00000100
#define purple 0b00000101
#define yellow 0b00000110
#define white 0b00000111 

// main program

int main (void)
{
DDRB = 0xFF; // set port B for output
PORTB = 1;
// infinite loop
while(1)

{
_delay_ms(50);
PORTB ++;
if (PORTB > 7)
PORTB = 1;
}

}

 

 

nr ADC.O value color
0 32 black
1 64 blue
2 96 green
3 128 red
4 160 cyan
5 192 yellow
6 224 purple
7 255 white

Things to Do

  • Use PWM to show more colors.