Remove spaces, rearange tabs

This commit is contained in:
ccppi 2024-03-14 21:37:51 +00:00
parent b79ebdd39d
commit 32a72c84fc

181
main.c
View File

@ -6,11 +6,9 @@
#include <avr/interrupt.h> #include <avr/interrupt.h>
#include <avr/power.h> #include <avr/power.h>
#define PATTERN_COUNT 4 #define PATTERN_COUNT 4
#define attiny45 #define attiny45
typedef struct typedef struct
{ {
unsigned char r; unsigned char r;
@ -18,8 +16,9 @@ typedef struct
unsigned char b; unsigned char b;
int time_hold; int time_hold;
}rgbval; }rgbval;
volatile uint16_t ms; volatile uint16_t ms;
volatile uint16_t counts; volatile uint16_t counts;
void InitTimer0(void); void InitTimer0(void);
void InitTimer1(void); void InitTimer1(void);
@ -47,114 +46,86 @@ ISR(TIMER0_OVF_vect)
{ {
count(); count();
} }
int main (void)
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}},
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,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,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,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}}, {{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}}}; {{87,119,122,10}, {95,87,122,10}, {52, 69, 56,10}, {83, 84, 72,10}}};
int i=0,i2=0,i3=0; int i=0,i2=0,i3=0;
int r,g,b = 0; int r,g,b = 0;
int set=0; int set=0;
int input=0; int input=0;
uint16_t pre_delay=0; uint16_t pre_delay=0;
ms =0; ms =0;
counts = 0; counts = 0;
//disable prescaler //disable prescaler
// CLKPR = (1<<CLKPR); maybe optimization removes this // CLKPR = (1<<CLKPR); maybe optimization removes this
// CLKPR = 0x00; // CLKPR = 0x00;
clock_prescale_set(clock_div_1); clock_prescale_set(clock_div_1);//replaces above 2 lines
//#######OC0A auf ausgang //#######OC0A auf ausgang
DDRB = (1 << PB0 )|(1<<PB1)|(1<<PB4);//data directions - output DDRB = (1 << PB0 )|(1<<PB1)|(1<<PB4);//data directions - output
PORTB |= (1<<PB2);//pullups PORTB |= (1<<PB2); //pullups
cli(); cli(); //DISABLE Global Interrupts
InitTimer0();
InitTimer0(); InitTimer1();
InitTimer1(); InitInterrupts();
//setrgb(100,100,100); sei(); //ENABLE Global Interrupts
InitInterrupts(); while(1)
sei(); {
while(1) for(i=0;i<PATTERN_COUNT;i++)
{ {
for(i=0;i<PATTERN_COUNT;i++) r = pattern[i2][i].r;
{ g = pattern[i2][i].g;
r = pattern[i2][i].r; b = pattern[i2][i].b;
g = pattern[i2][i].g; if(i==(PATTERN_COUNT-1)) {i= 0;}
b = pattern[i2][i].b; while(1)
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)
{ {
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++;} return 0;
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;
} }
void InitTimer0(void) void InitTimer0(void)
{ {
//#######Timer0-setup##### |Phase correct pwm //#######Timer0-setup##### |Phase correct pwm
@ -166,16 +137,16 @@ void InitTimer1(void)
{ {
//######Timer1-setup //######Timer1-setup
PLLCSR &= ~(1<<PCKE); 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 GTCCR = (1<<PWM1B)|(1<<COM1B1); //mode + overrun clear, Set on compare match
OCR1C = 255; // clear timer at 255 OCR1C = 255; // clear timer at 255
} }
void setrgb(unsigned int r,unsigned int g,unsigned int b) void setrgb(unsigned int r,unsigned int g,unsigned int b)
{ {
//depends on timer0 //depends on timer0
OCR0A = g;//green OCR0A = g;//green
OCR0B = r;//red OCR0B = r;//red
//depends on Timer1 //depends on Timer1
OCR1B = b;//blue OCR1B = b;//blue
} }
void InitInterrupts(void) void InitInterrupts(void)