v2.0
This commit is contained in:
parent
2910e8dc7f
commit
28dc9144c6
96
main.c
96
main.c
@ -11,26 +11,64 @@ typedef struct
|
||||
unsigned char b;
|
||||
int time_hold;
|
||||
}rgbval;
|
||||
void toogletimer()
|
||||
{
|
||||
static timer=1;
|
||||
if(timer==0)
|
||||
{
|
||||
TCCR0A &= ~((1<<COM0A1) | (1<<COM0B1));// |(1<<WGM01) | (1<<WGM00));
|
||||
TCCR1 &= ~(1<<COM1A0);
|
||||
GTCCR &= ~(1<<COM1B1);
|
||||
}
|
||||
else if(timer==1)
|
||||
{
|
||||
|
||||
DDRB = (1 << PB0 )|(1<<PB1)|(1<<PB4);
|
||||
TCCR0A = (1<<WGM01)|(1<<WGM00)|(1<<COM0A1)|(1<<COM0B1); //mode
|
||||
TCCR0B = (1<<CS01);//|(1<<CS02); //frequency /8
|
||||
//
|
||||
|
||||
TCCR1 = (1<<COM1A0)|(1<<CTC1)|(1<<CS12)|(1<<CS10);//|(1<<CS11)|(1<<CS13); //frequency
|
||||
GTCCR = (1<<PWM1B)|(1<<COM1B1); //mode + overrun clear
|
||||
OCR1C = 255; // clear timer at 255
|
||||
//######PWM_VALUE$
|
||||
//timer 0
|
||||
OCR0A = 128;
|
||||
OCR0B = 1;
|
||||
//timer 1
|
||||
OCR1B = 1;
|
||||
//######Configure Pullups
|
||||
PORTB |= (1<<PB2);
|
||||
|
||||
}
|
||||
timer = 1-timer;
|
||||
|
||||
}
|
||||
|
||||
int main (void) { // (2)
|
||||
|
||||
rgbval pattern[3][PATTERN_COUNT]={{{1,1,1,1000},{1,1,153,2000}, {200,50,39,1000}, {204,255,153,2000}},
|
||||
/*rgbval pattern2[PATTERN_COUNT]=*/{{1,1,1,1000}, {10,255,0,1000}, {1,1,255,2000}, {1,200,1,2000}},
|
||||
/*rgbval pattern3[PATTERN_COUNT]=*/{{1,1,5,1000}, {1,1,255,1000}, {1,1,5,1000}, {1,1,255,1000}}};
|
||||
rgbval pattern[6][PATTERN_COUNT]={ {{0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}},
|
||||
{{1,1,1,1}, {1,1,153,2}, {200,50,39,1}, {204,255,153,2}},
|
||||
/*rgbval pattern2[PATTERN_COUNT]=*/{{1,1,1,1}, {10,255,0,1}, {1,1,255,2}, {1,200,1,2}},
|
||||
/*rgbval pattern3[PATTERN_COUNT]=*/{{1,1,5,1}, {1,1,255,1}, {1,1,5,1}, {1,1,255,1}},
|
||||
{{252,102,3,1}, {161,67,47,1}, {118,120,74,1}, {83,120,74,2}},
|
||||
{{87,119,122,1}, {95,87,122,1}, {52, 69, 56,1}, {83, 84, 72,1}}};
|
||||
//rgbval *pattern=pattern1[0];
|
||||
int i=0,i2=0,i3;
|
||||
int r,g,b = 0;
|
||||
int set=0;
|
||||
int input=0;
|
||||
int stop_timer=3;
|
||||
//system_clock prescaler
|
||||
|
||||
//#######OC0A auf ausgang
|
||||
DDRB = (1 << PB0 )|(1<<PB1)|(1<<PB4);
|
||||
//#######Timer0-setup#####
|
||||
TCCR0A = (1<<WGM01)|(1<<WGM00)|(1<<COM0A1)|(1<<COM0B1); //mode
|
||||
TCCR0B = (1<<CS01);//|(1<<CS02); //frequency /1024
|
||||
TCCR0B = (1<<CS01);//|(1<<CS02); //frequency /8
|
||||
//
|
||||
|
||||
PLLCSR |= (1 << PLLE) | (1 << PCKE);
|
||||
// PLLCSR |= (1 << PLLE) | (1 << PCKE);
|
||||
//######Timer1-setup
|
||||
|
||||
TCCR1 = (1<<COM1A0)|(1<<CTC1)|(1<<CS12)|(1<<CS10);//|(1<<CS11)|(1<<CS13); //frequency
|
||||
@ -63,26 +101,45 @@ int main (void) { // (2)
|
||||
input=PINB;
|
||||
if(((input & (1<<PB2)) == 0 && set==0))
|
||||
{
|
||||
set=1;
|
||||
i=0;
|
||||
i2++;
|
||||
if(i2>2)
|
||||
{
|
||||
i2=0;
|
||||
}
|
||||
for(i3=0;i3<5;i3++)
|
||||
{
|
||||
OCR0A=1;OCR0B=1;OCR1B=1;
|
||||
_delay_ms(30);
|
||||
OCR0A=255;OCR0B=255;OCR1B=255;
|
||||
_delay_ms(30);
|
||||
}
|
||||
set=1;
|
||||
i=0;
|
||||
i2++;
|
||||
if(i2==6)
|
||||
{
|
||||
i2=0;
|
||||
stop_timer=1;
|
||||
}
|
||||
//cycle through and stop pwm at value 0
|
||||
if(stop_timer==1)
|
||||
{
|
||||
toogletimer();
|
||||
stop_timer=0;
|
||||
//PORTB &= ~((1<<PB0) | (1<<PB1) | (1<<PB4));
|
||||
}
|
||||
else if(stop_timer==0)
|
||||
{
|
||||
stop_timer=3;
|
||||
toogletimer();
|
||||
}
|
||||
if(i2>0)
|
||||
{
|
||||
//Visual feedback "mode change"
|
||||
for(i3=0;i3<i2;i3++)
|
||||
{
|
||||
OCR0A=1;OCR0B=1;OCR1B=1;
|
||||
_delay_ms(30);
|
||||
OCR0A=255;OCR0B=255;OCR1B=255;
|
||||
_delay_ms(30);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if((input & (1<<PB2) != 0))
|
||||
{
|
||||
set=0;
|
||||
|
||||
}
|
||||
if(i2>0)
|
||||
{
|
||||
if(r < pattern[i2][i+1].r) {r++;}
|
||||
if(r > pattern[i2][i+1].r) {r--;}
|
||||
if(g < pattern[i2][i+1].g) {g++;}
|
||||
@ -95,6 +152,7 @@ int main (void) { // (2)
|
||||
OCR1B = b;//blue
|
||||
_delay_ms(10);
|
||||
if(r == pattern[i2][i+1].r && g == pattern[i2][i+1].g && b == pattern[i2][i+1].b) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user