led-strip/main.c.1
2024-03-03 20:04:23 +01:00

70 lines
1.4 KiB
Groff

#define F_CPU 1000000UL
#include <util/delay.h>
#include <avr/io.h>
#define PATTERN_COUNT 4
typedef struct
{
unsigned char r;
unsigned char g;
unsigned char b;
int time_hold;
}rgbval;
int main (void) { // (2)
rgbval pattern[PATTERN_COUNT]={{128,255,0,1000}, {0,0,153,2000}, {200,50,39,1000}, {204,255,153,2000}};
int i=0;
int r,g,b = 0;
//#######OC0A auf ausgang
DDRB = (1 << PB0 )|(1<<PB1)|(1<<PB4);
//#######Timer0-setup#####
TCCR0A = (1<<WGM01)|(1<<WGM00)|(1<<COM0A1)|(1<<COM0B1); //mode
TCCR0B = (1<<CS01);//|(1<<CS02); //frequency /1024
//######Timer1-setup
TCCR1 = (1<<CTC1)|(1<<CS12);//|(1<<CS11)|(1<<CS13); //frequency
GTCCR = (1<<PWM1B)|(1<<COM1B1); //mode + overrun clear
OCR1C = 255; // clear timer at 255
//######PWM_VALUE$
//timer 0
OCR0A = 51;
OCR0B = 51;
//timer 1
OCR1B = 255;
while(1)
{
for(i=0;i<PATTERN_COUNT;i++)
{
r = pattern[i].r;
g = pattern[i].g;
b = pattern[i].b;
if(i==(PATTERN_COUNT-1)) {i= -1;}
while(1)
{
if(r < pattern[i+1].r) {r++;}
if(r > pattern[i+1].r) {r--;}
if(g < pattern[i+1].g) {g++;}
if(g > pattern[i+1].g) {g--;}
if(b < pattern[i+1].b) {b++;}
if(b > pattern[i+1].b) {b--;}
OCR0A = r;
OCR0B = g;
OCR1B = b;
_delay_ms(100);
if(r == pattern[i+1].r && g == pattern[i+1].g && b == pattern[i+1].b) break;
}
}
}
return 0;
}