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...
https://www.youtube.com/watch?v=YQRb4XUNtcU