Remove spaces, rearange tabs
This commit is contained in:
parent
b79ebdd39d
commit
32a72c84fc
47
main.c
47
main.c
@ -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,9 +46,8 @@ 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}},
|
||||||
@ -63,21 +61,18 @@ int main (void) { // (2)
|
|||||||
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();
|
||||||
//setrgb(100,100,100);
|
|
||||||
InitInterrupts();
|
InitInterrupts();
|
||||||
sei();
|
sei(); //ENABLE Global Interrupts
|
||||||
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;
|
||||||
@ -109,7 +103,7 @@ 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;
|
||||||
@ -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
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user