Remove spaces, rearange tabs

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

85
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,6 +16,7 @@ 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;
@ -47,37 +46,33 @@ 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();
sei();
while(1) while(1)
{ {
for(i=0;i<PATTERN_COUNT;i++) for(i=0;i<PATTERN_COUNT;i++)
@ -86,7 +81,6 @@ int main (void) { // (2)
g = pattern[i2][i].g; g = pattern[i2][i].g;
b = pattern[i2][i].b; b = pattern[i2][i].b;
if(i==(PATTERN_COUNT-1)) {i= 0;} if(i==(PATTERN_COUNT-1)) {i= 0;}
//reset timer counter
while(1) while(1)
{ {
input=PINB; input=PINB;
@ -99,7 +93,7 @@ int main (void) { // (2)
{ {
i2=0; i2=0;
} }
//Visual feedback "mode change" //Visual feedback "mode change"
for(i3=0;i3<i2;i3++) for(i3=0;i3<i2;i3++)
{ {
setrgb(0,0,0); setrgb(0,0,0);
@ -109,12 +103,12 @@ int main (void) { // (2)
pre_delay = ms; pre_delay = ms;
while((ms-pre_delay) < 200){}; while((ms-pre_delay) < 200){};
} }
}//end input handling }
else if(((input & (1<<PB2)) != 0)) else if(((input & (1<<PB2)) != 0))
{ {
set=0; set=0;
} }
//iterate throught pattern to the next ones //iterate throught pattern to the next ones
if(r < pattern[i2][i+1].r) {r++;} if(r < pattern[i2][i+1].r) {r++;}
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++;}
@ -122,39 +116,16 @@ int main (void) { // (2)
if(b < pattern[i2][i+1].b) {b++;} if(b < pattern[i2][i+1].b) {b++;}
if(b > pattern[i2][i+1].b) {b--;} if(b > pattern[i2][i+1].b) {b--;}
setrgb(r,g,b); setrgb(r,g,b);
//delay_ms(10); //read timer evaluate time since read in 1ms steps
//read timer evaluate time since read in 1ms steps //pre_delay = ms;
// pre_delay = ms; //while((ms-pre_delay) <1000);
// while((ms-pre_delay) <1000);
_delay_ms(30); _delay_ms(30);
if(r == pattern[i2][i+1].r && g == pattern[i2][i+1].g && b == pattern[i2][i+1].b) break; 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) void InitTimer0(void)
{ {
//#######Timer0-setup##### |Phase correct pwm //#######Timer0-setup##### |Phase correct pwm
@ -166,7 +137,7 @@ 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
} }