Pages

Wednesday, November 30, 2011

Valentine’s Heart LED Display with Proximity Sensor




    To use the touch-sensitive throbbing heart, just hold the circuit board by your chest (put the batteries in the adjoining pocket) and turn it on. The LEDs should start blinking at a normal rate. Now bring a hand close to the blinking LEDs, and the throbbing rate should start increasing. Keep bringing the hand closer to the circuit board and eventually touch the board and then take your hand away. Once you take your hand away, the LEDs should start blinking in the HAPPY mode, returning to normal throbbing after a few seconds.

for that program is here....
while(1)
{
if(mode==NORMAL)
{
PORTB &=0b11111000;
//off
mydelay(a+a+a+a);
PORTB|=0b00000111;
//on
mydelay(a+a);
PORTB &=0b11111000;
//off
mydelay(a+a);
PORTB |=0b00000111;
//on
mydelay(a+a);
time=0;
}
else if(mode==HAPPY)
{
if(state==1)
PORTB |=1<<2;
else if(state==5)
PORTB &= ~(1<<2);
if(state==5)
ORTB &=~(1<<1);
//Middle off
else if(state==2)
PORTB |=1<<1;
//Middle on
if(state==4)
PORTB &=~(1<<0);
//Outer off
else if(state==3)
PORTB |=1<<0;
//Outer on
mydelay(5*state);
state++;
if(state==6)
state=1;
time++;
if(time==100)
{
mode = NORMAL;
previous_mode
= NONE;
time=0;
a=20;
}
}
check();
}
void check(void)
{
TCCR0B = 0;//stop timer
TCNT0 = 0;//clear timer
i=0;
DDRB = 0b00010000;
PORTB &= ~(1<<3);
i=0;
TCCR0B = 1<<CS02|1<<CS00;
//Prescaled by 1024
while((PINB&(1<<3))&&(i<80))
{
i=TCNT0;
}
if(i>50)
{
if((previous_mode==NORMAL))
{
mode = HAPPY;
}
else a=20;
}
else if(i<50)
{
if(i<40)
previous_mode = NORMAL;
}
else previous_mode = NONE;
mode = NORMAL;
a=i/3;
}
PORTB |=1<<3;
DDRB = 0b00011111;
}
void mydelay(int var)
//delay of 10ms for var=1 at
//9.6 MHZ
{
unsigned char il, jl, kl;
for (il=0; il<var; il++)
for (jl=0; jl<251;jl++)
for (kl=0; kl<50; kl++)
asm(“NOP”);
}


Note: Only logical things are given in the program....

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...