Merge branch 'master' of ssh://repo.or.cz/srv/git/ctl24
[ctl24.git] / demo / main.c
blob7c8610bdee999afc9037e18f44c4f3f211601c0b
1 #include <avr/io.h>
2 #include <util/delay.h>
3 #include <stdlib.h>
4 #include <inttypes.h>
6 // xaffe was hereā€¦
8 uint8_t *red, *green, *blue;
10 void init_timer(void);
11 void demo_matrix(uint8_t*, uint8_t*, uint8_t*);
12 void display_matrix(void);
14 int main(void)
17 red=malloc(32 * sizeof(uint8_t));
18 green=malloc(32 * sizeof(uint8_t));
19 blue=malloc(32 * sizeof(uint8_t));
21 init_timer();
22 demo_matrix(red, green, blue);
24 // char s[4];
26 //PINs konfiguriern
27 DDRB = (1 << DDB1) | (1 << DDB2) | (1 << DDB3) | (1 << DDB4) | (1 << DDB5);
28 PORTB = (1 << PB3);//pwm
29 //pb3 - pwm; pb1 - SR out clk;pb2 - SR input;pb4 - SR reset;pb5 - SR shift clk
31 DDRC = (1 << DDC0) | (1 << DDC1) | (1 << DDC2) | (1 << DDC3);
32 //led anodes
34 DDRD = (1 << DDD0) | (1 << DDD5) | (1 << DDD6) | (1 << DDD7) ;
37 PORTB |= (1 << PB4); //reset
38 OCR2A=0;//hellikeit
39 // red[31]=1;
41 while(1)
43 display_matrix();
46 return 0;
50 void init_timer(void)
53 //Timer setzen, PWM
54 //Timer0 PinD6 OC0A
55 //---TCCR0A = (1 << COM0A1) | (1 << COM0B1) | (1 << WGM01) | (1 << WGM00); // FAST PWM ON OC0A OC0B
56 //---TCCR0B = (1 << CS00); // NO PRESCALER
57 //TIMSK0 = (1 << OCIE0A);//interupt enable
59 //OC0A green
60 //OC0B red
61 //OC2A blue
63 //Timer2 -- helligkeit
64 TCCR2A = (1 << COM2A1) | (1 << WGM21) | (1 << WGM20);
65 TCCR2B = (1 << CS20); // NO PRESCALER
66 //TIMSK0 = (1 << OCIE0A);//interupt enable
70 void demo_matrix(uint8_t* red, uint8_t* green, uint8_t* blue)
72 for(int y=0;y<32;y++)
74 red[y]=255/(y*8);
75 green[y]=255/(255-(y*8));
76 blue[y]=255/(255-(y*8));
81 void demo_matrix(uint8_t* red, uint8_t* green, uint8_t* blue)
83 for(int y=0;y<32;y++)
85 red[y]=y*8;
86 green[y]=255-y*8;
87 blue[y]=255-y*8;
92 void display_matrix(void)
94 uint8_t i,j,x,y,portc,color;
96 for(i=0; i<255; i++)
98 portc = 1;
100 for(y=0;y<32;y+=8)
103 for(x =0; x<8; x++)
105 PORTD &= ~((1<<PD5)|(1<<PD6)|(1<<PD7));
106 j=x+y;
108 if(red[j]&&!(i%red[j]))
109 PORTD |= (1<<PD5);
111 if(green[j]&&!(i%green[j]))
112 PORTD |= (1<<PD6);
114 if(blue[j]&&!(i%blue[j]))
115 PORTD |= (1<<PD7);
117 //shift
118 PORTB |= (1 << PB5);
119 PORTB &= ~ (1 << PB5);
122 //set line
123 PORTB |= (1 << PB1);
124 PORTB &= ~(1 << PB1);
126 PORTC |= 0x0F;
127 PORTC &= ~portc;
128 portc<<=1;
135 - timer interupt
136 + y vor x
137 - color map
138 - shift reg pwm!!!overkill 4x more lightness