Let's Make Robots!

LOVE DIY project

Flashes four 7-segment display which forms the word: "LOVE"

Hi guys...

 

I saw a blog about a cool project. It is powered from USB and simply displays the word "LOVE"... I was thinking about adding more dinamics because I hate something static... Static means boredome :(

 

I designed a simple double sided board for this with ATTiny2313...

 

I attached it here: LINK this is a Eagle board. ;) Simply can be edited to fit your desire

it looks like this:

 

here the button is connected wrong but I reatached it at the correct INT0 pin...

 

the main idea is to use a switch case function which is based on a contor applied by the interrupt of the button...

 

the main idea: if the button is pressed implement the contore with +1 and if it exeeds 5 it should be reseted

there are 4 blue SMD leds which blink if the button is pressed and plays around in the switch case as you can see in the video...

 unfortunatly in the video there is a huge cap a 250V one for filtering the spikes made by the button press, I ordered some SMDs... friday it will arrive...

 

I'll update this blog later next month because this started as a simple project as a birthday gift for my girlfriend and ended up as a nice little DIY...

 

special thanks goes to:

Tinhead - for his romanian help and basic minicode for this project; //now I understand really good the use of interrupts.

TeleFox - for explaining some codes;

and for Ro-Bot-X for his links and helps;

 

I'm proud to see how people are here to help each other... because of you from a simple tranzistor based robot I get so high that I already jumped over Arduino and started directly with AVRs... lower cost faster learning :)

 

If I could help you more than don't be shy to ask :)

 

I'm here to help guys

 

 

and now for the last, here is the main code:

again, thanks TinHead for the code... every macro setting and other are TinHead's glorry, I added just the codes and the pull-up settings and I set the loop in the INT0 with TinHead's help...

 

 

OK here is the final porgram updated ;)

The video indeed near :D

 

#include <avr/io.h>
#include <avr/interrupt.h>
#define F_CPU 4000000UL
#include <util/delay.h>

#define led_L PB7
#define led_O PB6
#define led_V PB5
#define led_E PB4
#define blue PB3
#define BUTTON_PIN PD2

//helping macros

#define read_pin(port, pin) port & (1<<pin)
#define output_low(port,pin) port &= ~(1<<pin)
#define output_high(port,pin) port |= (1<<pin)
#define set_input(portdir,pin) portdir &= ~(1<<pin)
#define set_output(portdir,pin) portdir |= (1<<pin)

int push_counter = 1;
int i, cont = 1, bbreak = 0;
void blink();
//void enableISR();




// Interrupt Service Request for INT0 vector
ISR(INT0_vect)
{
    push_counter++;
//    GIMSK &= ~(1<<INT0);
    if(push_counter>5)
    push_counter = 1; 
    cont = 1;
    i = 1;
    if(bit_is_set(PORTB, blue))
    output_low(PORTB, blue);
    while(i<=2)
    {
    output_high(PORTB, blue);
    _delay_ms(100);
    output_low(PORTB, blue);
    _delay_ms(100);
    i++;
    }
}


int main(void)
{
//seting up ports
set_output(DDRB, led_L);
set_output(DDRB, led_O);
set_output(DDRB, led_V);
set_output(DDRB, led_E);
set_output(DDRB, blue);
set_input(DDRD, BUTTON_PIN);

//setting pull-up to button pin
PORTD=0x04;




//blink blue SMDs one time to see if there was a reset
output_high(PORTB, blue);
_delay_ms(750);
output_low(PORTB, blue);

//setting interrupts
//cli disables all interrupts
cli();

//listening INT0 -> PD2 - further infos on datasheet
PCMSK |= (1<<PIND2);
MCUCR = (1<<ISC01) | (0<<ISC00);
GIMSK  |= (1<<INT0);

// sei activates global interrupts
sei();


while (1)
{
switch(push_counter)
{
case 1:

    output_high(PORTB, blue);
    _delay_ms(100);
    output_low(PORTB, blue);
    _delay_ms(10000);
//    enableISR();
    break;

case 2:

    if(bbreak==5||bbreak==6||bbreak==7||bbreak==8)
    output_low(PORTB, blue);
    else
    output_high(PORTB, blue);
    output_high(PORTB, led_L);
       output_high(PORTB, led_O);
    output_high(PORTB, led_V);
    output_high(PORTB, led_E);
    _delay_ms(750);
    output_low(PORTB, led_L);
    output_low(PORTB, led_O);
    output_low(PORTB, led_V);
    output_low(PORTB, led_E);
    _delay_ms(750);
    if(bbreak==8)
    bbreak=1;
    else
    bbreak++;
//    enableISR();
    break;

case 3:
    output_high(PORTB, led_L);
    output_high(PORTB, led_E);
    _delay_ms(500);
    output_high(PORTB, led_O);
    output_high(PORTB, led_V);
    _delay_ms(500);
    output_low(PORTB, led_L);
    output_low(PORTB, led_E);
    _delay_ms(500);
    output_low(PORTB, led_O);
    output_low(PORTB, led_V);
    _delay_ms(500);
    if(bit_is_set(PORTB, blue))
    output_low(PORTB, blue);
    while(i<=2)
    {
    output_high(PORTB, blue);
    _delay_ms(100);
    output_low(PORTB, blue);
    _delay_ms(100);
    i++;
    }

//    enableISR();
    break;

case 4:

    if(cont==0)
    {
    cont = 1;
    output_high(PORTB, blue);
    }
    else
    {
    cont=0;
    output_low(PORTB,blue);
    }
      output_high(PORTB, led_L);
       _delay_ms(100);
       output_low(PORTB, led_L);
       _delay_ms(100);
       output_high(PORTB, led_O);
       _delay_ms(100);
       output_low(PORTB, led_O);
      _delay_ms(100);
       output_high(PORTB, led_V);
    _delay_ms(100);
    output_low(PORTB, led_V);
    _delay_ms(100);
    output_high(PORTB, led_E);
    _delay_ms(100);
    output_low(PORTB, led_E);
    _delay_ms(100);
    output_high(PORTB, led_V);
    _delay_ms(100);
    output_low(PORTB, led_V);
    _delay_ms(100);
    output_high(PORTB, led_O);
    _delay_ms(100);
    output_low(PORTB, led_O);
    _delay_ms(100);
//    enableISR();
    break;

case 5:

    i=1;
    while(i<=2)
    {
    output_high(PORTB, led_L);
    _delay_ms(100);
    output_low(PORTB, led_L);
    _delay_ms(100);
    i++;
    }
    i=1;

    while(i<=2)
    {
    output_high(PORTB, led_O);
    _delay_ms(100);
    output_low(PORTB, led_O);
    _delay_ms(100);
    i++;
    }
    i=1;

    while(i<=2)
    {
    output_high(PORTB, led_V);
    _delay_ms(100);
    output_low(PORTB, led_V);
    _delay_ms(100);
    i++;
    }
    i=1;

    while(i<=2)
    {
    output_high(PORTB, led_E);
    _delay_ms(100);
    output_low(PORTB, led_E);
    _delay_ms(100);
    i++;
    }
    i=1;
    output_high(PORTB, led_E);
    _delay_ms(100);


    while(i<=2)
    {
    output_high(PORTB, led_L);
    _delay_ms(100);
    output_low(PORTB, led_L);
    _delay_ms(100);
    i++;
    }
    i=1;

    while(i<=2)
    {
    output_high(PORTB, led_O);
    _delay_ms(100);
    output_low(PORTB, led_O);
    _delay_ms(100);
    i++;
    }
    i=1;

    while(i<=2)
    {
    output_high(PORTB, led_V);
    _delay_ms(100);
    output_low(PORTB, led_V);
    _delay_ms(100);
    i++;
    }
    i=1;
    output_high(PORTB, led_V);
    _delay_ms(100);



    while(i<=2)
    {
    output_high(PORTB, led_L);
    _delay_ms(100);
    output_low(PORTB, led_L);
    _delay_ms(100);
    i++;
    }
    i=1;

    while(i<=2)
    {
    output_high(PORTB, led_O);
    _delay_ms(100);
    output_low(PORTB, led_O);
    _delay_ms(100);
    i++;
    }
    i=1;
    output_high(PORTB, led_O);
    _delay_ms(100);


    while(i<=2)
    {
    output_high(PORTB, led_L);
    _delay_ms(100);
    output_low(PORTB, led_L);
    _delay_ms(100);
    i++;
    }
    i=1;
    output_high(PORTB, led_L);
    _delay_ms(1000);
//break appart
    while(i<=2)
    {
    output_low(PORTB, led_E);
    _delay_ms(100);
    output_high(PORTB, led_E);
    _delay_ms(100);
    i++;
    }
    i=1;
    output_low(PORTB, led_E);
    _delay_ms(100);


    while(i<=2)
    {
    output_low(PORTB, led_V);
    _delay_ms(100);
    output_high(PORTB, led_V);
    _delay_ms(100);
    i++;
    }
    i=1;
    output_low(PORTB, led_V);


    while(i<=2)
    {
    output_low(PORTB, led_E);
    _delay_ms(100);
    output_high(PORTB, led_E);
    _delay_ms(100);
    i++;
    }
    i=1;
    output_low(PORTB, led_E);


    while(i<=2)
    {
    output_low(PORTB, led_O);
    _delay_ms(100);
    output_high(PORTB, led_O);
    _delay_ms(100);
    i++;
    }
    i=1;
    output_low(PORTB, led_O);



    while(i<=2)
    {
    output_low(PORTB, led_V);
    _delay_ms(100);
    output_high(PORTB, led_V);
    _delay_ms(100);
    i++;
    }
    i=1;
    output_low(PORTB, led_V);


    while(i<=2)
    {
    output_low(PORTB, led_E);
    _delay_ms(100);
    output_high(PORTB, led_E);
    _delay_ms(100);
    i++;
    }
    i=1;
    output_low(PORTB, led_E);



    while(i<=2)
    {
    output_low(PORTB, led_L);
    _delay_ms(100);
    output_high(PORTB, led_L);
    _delay_ms(100);
    i++;
    }
    i=1;
    output_low(PORTB, led_L);


    while(i<=2)
    {
    output_low(PORTB, led_O);
    _delay_ms(100);
    output_high(PORTB, led_O);
    _delay_ms(100);
    i++;
    }
    i=1;
    output_low(PORTB, led_O);



    while(i<=2)
    {
    output_low(PORTB, led_V);
    _delay_ms(100);
    output_high(PORTB, led_V);
    _delay_ms(100);
    i++;
    }
    i=1;
    output_low(PORTB, led_V);


    while(i<=2)
    {
    output_low(PORTB, led_E);
    _delay_ms(100);
    output_high(PORTB, led_E);
    _delay_ms(100);
    i++;
    }
    i=1;
    output_low(PORTB, led_E);
    _delay_ms(1000);
    blink();
    break;
}
}
}


void blink()
{
i=1;
while(i<=4)
{
output_high(PORTB, blue);
_delay_ms(100);
output_low(PORTB, blue);
_delay_ms(100);
i++;
}
}



//void enableISR()
//{
//    if((GIMSK & (1<<INT0)) == 0)
//    GIMSK |= (1<<INT0);
//}

 

UPDATE SEPTEMBER 23 :) Finally :D I did it... I manage to finish this nice project

as you see the video :) it looks great... I choose orange because my girlfriend loves orange...

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Love is in the LED... :D

 

Ok, really funny.

How much memory free do you have?

Try putting some code in a function.

For example:

instead of:
    while(i<=2)
    {
    output_low(PORTB, led_L);
    _delay_ms(100);
    output_high(PORTB, led_L);
    _delay_ms(100);
    i++;
    }
    i=1;
    output_low(PORTB, led_L);

try:

void function blink(int aLed)

{


    i=1;
    while(i<=2)
    {

    output_low(PORTB, aLed_L);
    _delay_ms(100);
    output_high(PORTB, aLed);
    _delay_ms(100);
    i++;
    }

    output_low(PORTB, aLed);

}

More, try replacing _delay_ms(100) with a function call; every delay_ms brings many assembly instructions.

 

Now, how much memory free do you have?

 

So prototyping to function some things will make more room? interesting... I was getting 99.8% percent full but never mind :D

 

I will recompile the code as soon as I install all avr things needed... I don't have nothing yet.. you know, new windows

Obviously calling a function instead of repeating the same 4 or more instructions free space.

Take a look at the assembly code generated from the compiler using functions and not.

Also, take a look at the assembly generated for the delay_xx instruction... a single instruction produce many assembly instructions.

This is my experience usin Microchip Pic, i think it's similar to the ATTiny2313.

 

LOVE on a 7-segment display? Should be LOUE or?

thats true but everyone should know what would it mean when it is ready :D

 

It will be something like "LOI_|E but thats fine :D take a look at the link near :P

... actually the macros are not mine except for the #define read_pin(port, pin) port & (1<<pin) if I'm remembering correctly, I found them somewhere when I first started so kudos to the guy/girl who wrote them in the first place.