Remove spaces, rearange tabs
This commit is contained in:
parent
b79ebdd39d
commit
32a72c84fc
181
main.c
181
main.c
@ -6,11 +6,9 @@
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/power.h>
|
||||
|
||||
|
||||
|
||||
|
||||
#define PATTERN_COUNT 4
|
||||
#define attiny45
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned char r;
|
||||
@ -18,8 +16,9 @@ typedef struct
|
||||
unsigned char b;
|
||||
int time_hold;
|
||||
}rgbval;
|
||||
|
||||
volatile uint16_t ms;
|
||||
volatile uint16_t counts;
|
||||
volatile uint16_t counts;
|
||||
|
||||
void InitTimer0(void);
|
||||
void InitTimer1(void);
|
||||
@ -47,114 +46,86 @@ ISR(TIMER0_OVF_vect)
|
||||
{
|
||||
count();
|
||||
}
|
||||
|
||||
int main (void) { // (2)
|
||||
|
||||
rgbval pattern[6][PATTERN_COUNT]={ {{0,0,0,100}, {0,0,0,100}, {0,0,0,100}, {0,0,0,100}},
|
||||
int main (void)
|
||||
{
|
||||
rgbval pattern[6][PATTERN_COUNT]={ {{0,0,0,100}, {0,0,0,100}, {0,0,0,100}, {0,0,0,100}},
|
||||
{{1,1,1,10}, {1,1,153,20}, {200,50,39,10}, {204,255,153,20}},
|
||||
{{1,50,50,10}, {10,255,0,10}, {80,200,0,20}, {200,200,1,20}},
|
||||
{{1,1,5,10}, {1,1,255,10}, {1,1,5,10}, {1,1,255,10}},
|
||||
{{1,50,50,10}, {10,255,0,10}, {80,200,0,20}, {200,200,1,20}},
|
||||
{{1,1,5,10}, {1,1,255,10}, {1,1,5,10}, {1,1,255,10}},
|
||||
{{252,102,3,10}, {161,67,47,10}, {118,120,74,10}, {83,120,74,20}},
|
||||
{{87,119,122,10}, {95,87,122,10}, {52, 69, 56,10}, {83, 84, 72,10}}};
|
||||
int i=0,i2=0,i3=0;
|
||||
int r,g,b = 0;
|
||||
int set=0;
|
||||
int input=0;
|
||||
uint16_t pre_delay=0;
|
||||
ms =0;
|
||||
counts = 0;
|
||||
|
||||
{{87,119,122,10}, {95,87,122,10}, {52, 69, 56,10}, {83, 84, 72,10}}};
|
||||
int i=0,i2=0,i3=0;
|
||||
int r,g,b = 0;
|
||||
int set=0;
|
||||
int input=0;
|
||||
uint16_t pre_delay=0;
|
||||
ms =0;
|
||||
counts = 0;
|
||||
//disable prescaler
|
||||
// CLKPR = (1<<CLKPR); maybe optimization removes this
|
||||
// CLKPR = 0x00;
|
||||
clock_prescale_set(clock_div_1);
|
||||
clock_prescale_set(clock_div_1);//replaces above 2 lines
|
||||
//#######OC0A auf ausgang
|
||||
DDRB = (1 << PB0 )|(1<<PB1)|(1<<PB4);//data directions - output
|
||||
PORTB |= (1<<PB2);//pullups
|
||||
cli();
|
||||
|
||||
InitTimer0();
|
||||
InitTimer1();
|
||||
//setrgb(100,100,100);
|
||||
InitInterrupts();
|
||||
sei();
|
||||
while(1)
|
||||
{
|
||||
for(i=0;i<PATTERN_COUNT;i++)
|
||||
{
|
||||
r = pattern[i2][i].r;
|
||||
g = pattern[i2][i].g;
|
||||
b = pattern[i2][i].b;
|
||||
if(i==(PATTERN_COUNT-1)) {i= 0;}
|
||||
//reset timer counter
|
||||
while(1)
|
||||
{
|
||||
input=PINB;
|
||||
if(((input & (1<<PB2)) == 0 && set==0))
|
||||
{
|
||||
set=1;
|
||||
i=0;
|
||||
i2++;
|
||||
if(i2==6)
|
||||
DDRB = (1 << PB0 )|(1<<PB1)|(1<<PB4);//data directions - output
|
||||
PORTB |= (1<<PB2); //pullups
|
||||
cli(); //DISABLE Global Interrupts
|
||||
InitTimer0();
|
||||
InitTimer1();
|
||||
InitInterrupts();
|
||||
sei(); //ENABLE Global Interrupts
|
||||
while(1)
|
||||
{
|
||||
for(i=0;i<PATTERN_COUNT;i++)
|
||||
{
|
||||
r = pattern[i2][i].r;
|
||||
g = pattern[i2][i].g;
|
||||
b = pattern[i2][i].b;
|
||||
if(i==(PATTERN_COUNT-1)) {i= 0;}
|
||||
while(1)
|
||||
{
|
||||
i2=0;
|
||||
input=PINB;
|
||||
if(((input & (1<<PB2)) == 0 && set==0))
|
||||
{
|
||||
set=1;
|
||||
i=0;
|
||||
i2++;
|
||||
if(i2==6)
|
||||
{
|
||||
i2=0;
|
||||
}
|
||||
//Visual feedback "mode change"
|
||||
for(i3=0;i3<i2;i3++)
|
||||
{
|
||||
setrgb(0,0,0);
|
||||
pre_delay = ms;
|
||||
while((ms-pre_delay) < 200);
|
||||
setrgb(0,200,0);
|
||||
pre_delay = ms;
|
||||
while((ms-pre_delay) < 200){};
|
||||
}
|
||||
}
|
||||
else if(((input & (1<<PB2)) != 0))
|
||||
{
|
||||
set=0;
|
||||
}
|
||||
//iterate throught pattern to the next ones
|
||||
if(r < pattern[i2][i+1].r) {r++;}
|
||||
if(r > pattern[i2][i+1].r) {r--;}
|
||||
if(g < pattern[i2][i+1].g) {g++;}
|
||||
if(g > pattern[i2][i+1].g) {g--;}
|
||||
if(b < pattern[i2][i+1].b) {b++;}
|
||||
if(b > pattern[i2][i+1].b) {b--;}
|
||||
setrgb(r,g,b);
|
||||
//read timer evaluate time since read in 1ms steps
|
||||
//pre_delay = ms;
|
||||
//while((ms-pre_delay) <1000);
|
||||
_delay_ms(30);
|
||||
if(r == pattern[i2][i+1].r && g == pattern[i2][i+1].g && b == pattern[i2][i+1].b) break;
|
||||
}
|
||||
//Visual feedback "mode change"
|
||||
for(i3=0;i3<i2;i3++)
|
||||
{
|
||||
setrgb(0,0,0);
|
||||
pre_delay = ms;
|
||||
while((ms-pre_delay) < 200);
|
||||
setrgb(0,200,0);
|
||||
pre_delay = ms;
|
||||
while((ms-pre_delay) < 200){};
|
||||
}
|
||||
}//end input handling
|
||||
else if(((input & (1<<PB2)) != 0))
|
||||
{
|
||||
set=0;
|
||||
}
|
||||
//iterate throught pattern to the next ones
|
||||
if(r < pattern[i2][i+1].r) {r++;}
|
||||
if(r > pattern[i2][i+1].r) {r--;}
|
||||
if(g < pattern[i2][i+1].g) {g++;}
|
||||
if(g > pattern[i2][i+1].g) {g--;}
|
||||
if(b < pattern[i2][i+1].b) {b++;}
|
||||
if(b > pattern[i2][i+1].b) {b--;}
|
||||
setrgb(r,g,b);
|
||||
//delay_ms(10);
|
||||
//read timer evaluate time since read in 1ms steps
|
||||
// pre_delay = ms;
|
||||
// while((ms-pre_delay) <1000);
|
||||
_delay_ms(30);
|
||||
if(r == pattern[i2][i+1].r && g == pattern[i2][i+1].g && b == pattern[i2][i+1].b) break;
|
||||
}
|
||||
|
||||
// pre_delay = ms;
|
||||
// while((ms-pre_delay) < 10);
|
||||
}
|
||||
|
||||
/* pre_delay = ms;
|
||||
setrgb(255,0,0);
|
||||
while((ms-pre_delay) < 100);
|
||||
|
||||
pre_delay = ms;
|
||||
setrgb(0,255,0);
|
||||
|
||||
while((ms-pre_delay) < 100);
|
||||
pre_delay = ms;
|
||||
setrgb(0,0,0);
|
||||
while((ms-pre_delay) < 100);*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void InitTimer0(void)
|
||||
{
|
||||
//#######Timer0-setup##### |Phase correct pwm
|
||||
@ -166,16 +137,16 @@ void InitTimer1(void)
|
||||
{
|
||||
//######Timer1-setup
|
||||
PLLCSR &= ~(1<<PCKE);
|
||||
TCCR1 = (1<<COM1A0)|(1<<COM1A1)|(1<<CS12)|(1<<CS10)|(1<<CS11);//(1<<CS10)|(1<<CS12);//|(1<<CS13); //frequencyi //iinverting PWM because 0 dtc not possible
|
||||
TCCR1 = (1<<COM1A0)|(1<<COM1A1)|(1<<CS12)|(1<<CS10)|(1<<CS11);//(1<<CS10)|(1<<CS12);//|(1<<CS13); //frequencyi //inverting PWM because 0 dtc not possible
|
||||
GTCCR = (1<<PWM1B)|(1<<COM1B1); //mode + overrun clear, Set on compare match
|
||||
OCR1C = 255; // clear timer at 255
|
||||
}
|
||||
void setrgb(unsigned int r,unsigned int g,unsigned int b)
|
||||
{
|
||||
//depends on timer0
|
||||
//depends on timer0
|
||||
OCR0A = g;//green
|
||||
OCR0B = r;//red
|
||||
//depends on Timer1
|
||||
//depends on Timer1
|
||||
OCR1B = b;//blue
|
||||
}
|
||||
void InitInterrupts(void)
|
||||
|
Loading…
Reference in New Issue
Block a user