Remove spaces, rearange tabs

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

47
main.c
View File

@ -6,11 +6,9 @@
#include <avr/interrupt.h>
#include <avr/power.h>
#define PATTERN_COUNT 4
#define attiny45
typedef struct
{
unsigned char r;
@ -18,6 +16,7 @@ typedef struct
unsigned char b;
int time_hold;
}rgbval;
volatile uint16_t ms;
volatile uint16_t counts;
@ -47,9 +46,8 @@ ISR(TIMER0_OVF_vect)
{
count();
}
int main (void) { // (2)
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}},
@ -63,21 +61,18 @@ int main (void) { // (2)
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();
cli(); //DISABLE Global Interrupts
InitTimer0();
InitTimer1();
//setrgb(100,100,100);
InitInterrupts();
sei();
sei(); //ENABLE Global Interrupts
while(1)
{
for(i=0;i<PATTERN_COUNT;i++)
@ -86,7 +81,6 @@ int main (void) { // (2)
g = pattern[i2][i].g;
b = pattern[i2][i].b;
if(i==(PATTERN_COUNT-1)) {i= 0;}
//reset timer counter
while(1)
{
input=PINB;
@ -109,7 +103,7 @@ int main (void) { // (2)
pre_delay = ms;
while((ms-pre_delay) < 200){};
}
}//end input handling
}
else if(((input & (1<<PB2)) != 0))
{
set=0;
@ -122,39 +116,16 @@ int main (void) { // (2)
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)
{
//#######Timer0-setup##### |Phase correct pwm
@ -166,7 +137,7 @@ 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
}