LED candle avr

This is a simple project, called  LED candle. I will be using yellow LED’s of 2 and a simple PWM code that runs on AVR (ATmega328p) chip make’s the LED flickering that almost looks like candle.  😛  for candle I will be using  LED’s+translucent paper.

two-yellow-leds       translucent-paper

 

led-candle

LED candle

 

circuit:

led-candle

 

code is very straight , Simple PWM code runs on ATmega48/328p

#define F_CPU 1000000UL
#include avr/io.h
#include util/delay.h

#include avr/interrupt.h

void timer1_init(void);

void timer1_init()
{
DDRB |= 1<<PINB1; //
DDRB |= 1<<PINB2;

TCCR1A |= 1<<COM1A1 | 1<<WGM11; //
TCCR1A |= 1<<COM1B1;
TCCR1B |= 1<<WGM12 | 1<<WGM13 | 1<<CS10; //
ICR1 = 49; //top value
}

int main(void)
{
timer1_init();

_delay_ms(1000);
while(1)
{
OCR1B = rand() % 47 + 1;

OCR1A = rand() % 47 + 1;

}
}

video:  

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s