Rev 53 | Rev 55 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 53 | Rev 54 | ||
---|---|---|---|
1 | //############################################################################ |
1 | //############################################################################ |
2 | // - PWM CTRL |
2 | // - PWM CTRL |
3 | // - Main |
3 | // - Main |
4 | // - ATMEGA8 mit 8MHz |
4 | // - ATMEGA8 mit 8MHz |
5 | // - Nur für den privaten Gebrauch |
5 | // - Nur für den privaten Gebrauch |
6 | // - Keine Garantie auf Fehlerfreiheit |
6 | // - Keine Garantie auf Fehlerfreiheit |
7 | // - Kommerzielle Nutzung nur mit meiner Zustimmung |
7 | // - Kommerzielle Nutzung nur mit meiner Zustimmung |
8 | // - walter Meyer @ www.freakware.de |
8 | // - walter Meyer @ www.freakware.de |
9 | // - 11.12.2007 |
9 | // - 11.12.2007 |
10 | // - Make sure Fuses are programmed for internal 8 MHz RC Oscilator |
10 | // - Make sure Fuses are programmed for internal 8 MHz RC Oscilator |
11 | //############################################################################*/ |
11 | //############################################################################*/ |
12 | 12 | ||
13 | #include "main.h" |
13 | #include "main.h" |
14 | #include "uart.h" |
14 | #include "uart.h" |
15 | #include "twislave.h" |
15 | #include "twislave.h" |
16 | 16 | ||
17 | volatile unsigned int ppm_signal = 1500; |
17 | volatile unsigned int ppm_signal = 1500; |
18 | volatile unsigned char ppm_new = 0; |
18 | volatile unsigned char ppm_new = 0; |
19 | volatile unsigned char TMR1OvF = 0; |
19 | volatile unsigned char TMR1OvF = 0; |
20 | volatile unsigned int TMR1MS; |
20 | volatile unsigned int TMR1MS; |
21 | volatile unsigned char ch0; |
21 | volatile unsigned char ch0; |
22 | volatile unsigned char ch1; |
22 | volatile unsigned char ch1; |
23 | volatile unsigned char ch2; |
23 | volatile unsigned char ch2; |
24 | volatile unsigned char ch3; |
24 | volatile unsigned char ch3; |
25 | volatile unsigned char ch4; |
25 | volatile unsigned char ch4; |
26 | volatile unsigned char ch5; |
26 | volatile unsigned char ch5; |
27 | volatile unsigned char ch0_tmp; |
27 | volatile unsigned char ch0_tmp; |
28 | volatile unsigned char ch1_tmp; |
28 | volatile unsigned char ch1_tmp; |
29 | volatile unsigned char ch2_tmp; |
29 | volatile unsigned char ch2_tmp; |
30 | volatile unsigned char ch3_tmp; |
30 | volatile unsigned char ch3_tmp; |
31 | volatile unsigned char ch4_tmp; |
31 | volatile unsigned char ch4_tmp; |
32 | volatile unsigned char ch5_tmp; |
32 | volatile unsigned char ch5_tmp; |
33 | 33 | ||
34 | 34 | ||
35 | unsigned int timer; |
35 | unsigned int timer; |
36 | 36 | ||
37 | SIGNAL(SIG_OVERFLOW1) |
37 | SIGNAL(SIG_OVERFLOW1) |
38 | { |
38 | { |
39 | TMR1OvF++; |
39 | TMR1OvF++; |
40 | } |
40 | } |
41 | 41 | ||
42 | 42 | ||
43 | SIGNAL(SIG_INPUT_CAPTURE1) |
43 | SIGNAL(SIG_INPUT_CAPTURE1) |
44 | { |
44 | { |
45 | static unsigned int pos_ICR; |
45 | static unsigned int pos_ICR; |
46 | static unsigned int ppm; |
46 | static unsigned int ppm; |
47 | 47 | ||
48 | if ((TCCR1B & (1<<ICES1)) != 0) //rising edge |
48 | if ((TCCR1B & (1<<ICES1)) != 0) //rising edge |
49 | { |
49 | { |
50 | TCCR1B &= ~(1<<ICES1); //set falling egde |
50 | TCCR1B &= ~(1<<ICES1); //set falling egde |
51 | TMR1OvF = 0; |
51 | TMR1OvF = 0; |
52 | pos_ICR = ICR1; |
52 | pos_ICR = ICR1; |
53 | } |
53 | } |
54 | else //falling edge |
54 | else //falling edge |
55 | { |
55 | { |
56 | TCCR1B |= (1<<ICES1); //set rising egde |
56 | TCCR1B |= (1<<ICES1); //set rising egde |
57 | ppm = (ICR1 - pos_ICR + (int) TMR1OvF * 65536); |
57 | ppm = (ICR1 - pos_ICR + (int) TMR1OvF * 65536); |
58 | if ((ppm > 600) && (ppm < 2400)) |
58 | if ((ppm > 600) && (ppm < 2400)) |
59 | { |
59 | { |
60 | if (ppm > 2100) ppm = 2100; |
60 | if (ppm > 2100) ppm = 2100; |
61 | if (ppm < 900) ppm = 900; |
61 | if (ppm < 900) ppm = 900; |
62 | ppm = (ppm_signal * 7 + ppm) / 8; |
62 | ppm = (ppm_signal * 3 + ppm) / 4; |
63 | ppm_signal = ppm; |
63 | ppm_signal = ppm; |
64 | ppm_new = 1; |
64 | if (ppm_new < 50) ppm_new++; |
65 | } |
65 | } |
66 | 66 | ||
67 | } |
67 | } |
68 | 68 | ||
69 | } |
69 | } |
70 | 70 | ||
71 | 71 | ||
72 | 72 | ||
73 | 73 | ||
74 | 74 | ||
75 | SIGNAL(SIG_OVERFLOW0) |
75 | SIGNAL(SIG_OVERFLOW0) |
76 | { |
76 | { |
77 | // this function is called every 32us, |
77 | // this function is called every 32us, |
78 | // it is very important that it's execution time is as short as possible |
78 | // it is very important that it's execution time is as short as possible |
79 | // currently it's about 20us |
79 | // currently it's about 20us |
80 | 80 | ||
81 | static unsigned char counter = 254; |
81 | static unsigned char counter = 254; |
82 | static unsigned char ms1 = 0; |
82 | static unsigned char ms1 = 0; |
83 | unsigned char PORTB_BAK; |
83 | unsigned char PORTB_BAK; |
84 | unsigned char PORTD_BAK; |
84 | unsigned char PORTD_BAK; |
85 | 85 | ||
86 | PORTB_BAK = PORTB; |
86 | PORTB_BAK = PORTB; |
87 | PORTD_BAK = PORTD; |
87 | PORTD_BAK = PORTD; |
88 | 88 | ||
89 | if (counter++ == 254) |
89 | if (counter++ == 254) |
90 | { |
90 | { |
91 | PORTB_BAK LEDON (CH0_B | CH1_B | CH2_B); |
91 | PORTB_BAK LEDON (CH0_B | CH1_B | CH2_B); |
92 | PORTD_BAK LEDON (CH3_D | CH4_D | CH5_D); |
92 | PORTD_BAK LEDON (CH3_D | CH4_D | CH5_D); |
93 | ch0_tmp = ch0; |
93 | ch0_tmp = ch0; |
94 | ch1_tmp = ch1; |
94 | ch1_tmp = ch1; |
95 | ch2_tmp = ch2; |
95 | ch2_tmp = ch2; |
96 | ch3_tmp = ch3; |
96 | ch3_tmp = ch3; |
97 | ch4_tmp = ch4; |
97 | ch4_tmp = ch4; |
98 | ch5_tmp = ch5; |
98 | ch5_tmp = ch5; |
99 | counter = 0; |
99 | counter = 0; |
100 | } |
100 | } |
101 | 101 | ||
102 | if (ch0_tmp == counter) PORTB_BAK LEDOFF CH0_B; |
102 | if (ch0_tmp == counter) PORTB_BAK LEDOFF CH0_B; |
103 | if (ch1_tmp == counter) PORTB_BAK LEDOFF CH1_B; |
103 | if (ch1_tmp == counter) PORTB_BAK LEDOFF CH1_B; |
104 | if (ch2_tmp == counter) PORTB_BAK LEDOFF CH2_B; |
104 | if (ch2_tmp == counter) PORTB_BAK LEDOFF CH2_B; |
105 | if (ch3_tmp == counter) PORTD_BAK LEDOFF CH3_D; |
105 | if (ch3_tmp == counter) PORTD_BAK LEDOFF CH3_D; |
106 | if (ch4_tmp == counter) PORTD_BAK LEDOFF CH4_D; |
106 | if (ch4_tmp == counter) PORTD_BAK LEDOFF CH4_D; |
107 | if (ch5_tmp == counter) PORTD_BAK LEDOFF CH5_D; |
107 | if (ch5_tmp == counter) PORTD_BAK LEDOFF CH5_D; |
108 | 108 | ||
109 | PORTB = PORTB_BAK; |
109 | PORTB = PORTB_BAK; |
110 | PORTD = PORTD_BAK; |
110 | PORTD = PORTD_BAK; |
- | 111 | ||
111 | 112 | ||
112 | if (ms1++ == 32) |
113 | if (ms1++ == 32) |
113 | { |
114 | { |
114 | ms1=0; |
115 | ms1=0; |
115 | TMR1MS++; |
116 | TMR1MS++; |
116 | } |
117 | } |
117 | 118 | ||
118 | 119 | ||
119 | 120 | ||
120 | 121 | ||
121 | } |
122 | } |
122 | 123 | ||
123 | 124 | ||
124 | 125 | ||
125 | unsigned int SetDelay (unsigned int t) |
126 | unsigned int SetDelay (unsigned int t) |
126 | { |
127 | { |
127 | unsigned char temp_hi; |
128 | unsigned char temp_hi; |
128 | unsigned char temp_lo; |
129 | unsigned char temp_lo; |
129 | 130 | ||
130 | temp_hi = (TMR1MS >> 8); |
131 | temp_hi = (TMR1MS >> 8); |
131 | temp_lo = (TMR1MS & 0xff); |
132 | temp_lo = (TMR1MS & 0xff); |
132 | if (temp_hi != (TMR1MS >> 8)) temp_hi = (TMR1MS >> 8); |
133 | if (temp_hi != (TMR1MS >> 8)) temp_hi = (TMR1MS >> 8); |
133 | 134 | ||
134 | return(((temp_hi << 8) | temp_lo) + t + 1); |
135 | return(((temp_hi << 8) | temp_lo) + t + 1); |
135 | 136 | ||
136 | } |
137 | } |
137 | 138 | ||
- | 139 | ||
138 | 140 | ||
139 | char CheckDelay(unsigned int t) |
141 | char CheckDelay(unsigned int t) |
140 | { |
142 | { |
141 | unsigned char temp_hi; |
143 | unsigned char temp_hi; |
142 | unsigned char temp_lo; |
144 | unsigned char temp_lo; |
143 | 145 | ||
144 | temp_hi = (TMR1MS >> 8); |
146 | temp_hi = (TMR1MS >> 8); |
145 | temp_lo = (TMR1MS & 0xff); |
147 | temp_lo = (TMR1MS & 0xff); |
146 | if (temp_hi != (TMR1MS >> 8)) temp_hi = (TMR1MS >> 8); |
148 | if (temp_hi != (TMR1MS >> 8)) temp_hi = (TMR1MS >> 8); |
147 | 149 | ||
148 | return(((t - ((temp_hi << 8) | temp_lo)) & 0x8000) >> 9); |
150 | return(((t - ((temp_hi << 8) | temp_lo)) & 0x8000) >> 9); |
149 | 151 | ||
150 | } |
152 | } |
151 | 153 | ||
152 | 154 | ||
153 | 155 | ||
154 | 156 | ||
155 | /*##############################################################################*/ |
157 | /*##############################################################################*/ |
156 | void StartPWM(void) |
158 | void StartPWM(void) |
157 | { |
159 | { |
158 | //Timer 0 Config for getting right timing for IR Pattern |
160 | //Timer 0 Config for getting right timing for IR Pattern |
159 | TCCR0 = (0<<CS02)|(0<<CS01)|(1<<CS00); // (@8MHz) = 1/8us Clk = 256/8 = 32us overflow |
161 | TCCR0 = (0<<CS02)|(0<<CS01)|(1<<CS00); // (@8MHz) = 1/8us Clk = 256/8 = 32us overflow |
160 | TIMSK setbit (1<<TOIE0); // enable Int |
162 | TIMSK setbit (1<<TOIE0); // enable Int |
161 | 163 | ||
162 | } |
164 | } |
163 | 165 | ||
164 | 166 | ||
165 | 167 | ||
166 | /*##############################################################################*/ |
168 | /*##############################################################################*/ |
167 | void StartPPM(void) |
169 | void StartPPM(void) |
168 | { |
170 | { |
169 | 171 | ||
170 | //global timer1 Config |
172 | //global timer1 Config |
171 | TCCR1A = (0<<COM1A1)|(0<<COM1A0)|(0<<COM1B1)|(0<<COM1B0)| |
173 | TCCR1A = (0<<COM1A1)|(0<<COM1A0)|(0<<COM1B1)|(0<<COM1B0)| |
172 | (0<<FOC1A) |(0<<FOC1B) |(0<<WGM10) |(0<<WGM11); |
174 | (0<<FOC1A) |(0<<FOC1B) |(0<<WGM10) |(0<<WGM11); |
173 | TCCR1B = (1<<ICNC1)|(1<<ICES1)|(0<<WGM13)| |
175 | TCCR1B = (1<<ICNC1)|(1<<ICES1)|(0<<WGM13)| |
174 | (0<<WGM12)|(0<<CS12)|(1<<CS11)|(0<<CS10); //ICP_POS_FLANKE |
176 | (0<<WGM12)|(0<<CS12)|(1<<CS11)|(0<<CS10); //ICP_POS_FLANKE |
175 | 177 | ||
176 | // interrupts |
178 | // interrupts |
177 | TIMSK |= (1<<TICIE1)|(1<<TOIE1); //ICP_INT_ENABLE and TIMER1_INT_ENABLE |
179 | TIMSK |= (1<<TICIE1)|(1<<TOIE1); //ICP_INT_ENABLE and TIMER1_INT_ENABLE |
178 | 180 | ||
179 | } |
181 | } |
180 | 182 | ||
181 | 183 | ||
182 | 184 | ||
183 | /*##############################################################################*/ |
185 | /*##############################################################################*/ |
184 | int GetPPM(void) |
186 | unsigned int GetPPM(void) |
185 | { |
187 | { |
186 | //this routines seems to be nesseccary, as reading a 16 bit value |
188 | //this routines seems to be nesseccary, as reading a 16 bit value |
187 | //on a 8 bit machine is not atomic, so if an interrupt apears between reading |
189 | //on a 8 bit machine is not atomic, so if an interrupt apears between reading |
188 | //low and high byte of the 16 bit value a wrong result is possible |
190 | //low and high byte of the 16 bit value a wrong result is possible |
189 | 191 | ||
190 | unsigned char intmask; |
192 | unsigned char temp_hi; |
191 | unsigned int ppm_temp; |
- | |
192 | 193 | unsigned char temp_lo; |
|
193 | intmask = TIMSK; //backup interupt enable bits |
194 | |
194 | TIMSK &= ~(1<<TICIE1); //disable ppm interrupt |
195 | temp_hi = (ppm_signal >> 8); |
195 | ppm_temp = ppm_signal; |
196 | temp_lo = (ppm_signal & 0xff); |
196 | TIMSK = intmask; //restore interupt enable bits |
197 | if (temp_hi != (ppm_signal >> 8)) temp_hi = (ppm_signal >> 8); |
197 | return(ppm_temp); //return ppm_signal |
198 | return( (temp_hi << 8) | temp_lo); |
198 | 199 | ||
199 | } |
200 | } |
200 | 201 | ||
201 | 202 | ||
202 | /*##############################################################################*/ |
203 | /*##############################################################################*/ |
203 | // MAIN |
204 | // MAIN |
204 | /*##############################################################################*/ |
205 | /*##############################################################################*/ |
205 | int main (void) |
206 | int main (void) |
206 | { |
207 | { |
- | 208 | ||
- | 209 | #define step 128 |
|
207 | unsigned int i; |
210 | #define mul 2 |
- | 211 | ||
- | 212 | #define sigeepadr 0x00 |
|
- | 213 | #define mineepadr 0x20 |
|
- | 214 | #define maxeepadr 0x22 |
|
- | 215 | #define eepsig 0x55aa |
|
- | 216 | ||
- | 217 | ||
- | 218 | ||
208 | unsigned int ppm; |
219 | unsigned int ppm; |
- | 220 | unsigned int setupdly; |
|
209 | unsigned char colorState; |
221 | unsigned int ppmtodly; |
- | 222 | unsigned int lmax; |
|
- | 223 | unsigned int lmin; |
|
- | 224 | unsigned int max; |
|
- | 225 | unsigned int min; |
|
- | 226 | unsigned int sig; |
|
210 | unsigned char nextcolorState=0; |
227 | unsigned char setup; |
- | 228 | ||
211 | 229 | ||
212 | DDRB = (CH0_B|CH1_B|CH2_B); |
230 | DDRB = (CH0_B|CH1_B|CH2_B); |
213 | PORTB = 0x00; |
231 | PORTB = 0x00; |
214 | 232 | ||
215 | DDRC = (ledred); |
233 | DDRC = (ledred); |
216 | PORTC = 0x00; |
234 | PORTC = 0x00; |
217 | 235 | ||
218 | DDRD = (ledgreen|CH3_D|CH4_D|CH5_D); |
236 | DDRD = (ledgreen|CH3_D|CH4_D|CH5_D); |
219 | PORTD = 0x00; |
237 | PORTD = 0x00; |
220 | 238 | ||
221 | ch0 = 0; |
239 | ch0 = 0; |
222 | ch1 = 0; |
240 | ch1 = 0; |
223 | ch2 = 0; |
241 | ch2 = 0; |
224 | ch3 = 0; |
242 | ch3 = 0; |
225 | ch4 = 0; |
243 | ch4 = 0; |
226 | ch5 = 0; |
244 | ch5 = 0; |
- | 245 | ||
- | 246 | lmax = 0x0000; |
|
- | 247 | lmin = 0xffff; |
|
227 | 248 | ||
228 | //StartUART(); |
249 | StartUART(); |
229 | StartPPM(); |
250 | StartPPM(); |
230 | //StartI2C(); |
251 | //StartI2C(); |
231 | StartPWM(); |
252 | StartPWM(); |
232 | sei(); |
253 | sei(); |
233 | 254 | ||
234 | 255 | ||
- | 256 | min = 1100; |
|
- | 257 | max = 1900; |
|
- | 258 | ||
- | 259 | if (eeprom_read_word(sigeepadr) != eepsig) |
|
- | 260 | { |
|
- | 261 | eeprom_write_word(mineepadr, min); |
|
- | 262 | eeprom_write_word(maxeepadr, max); |
|
- | 263 | eeprom_write_word(sigeepadr, eepsig); |
|
- | 264 | } |
|
- | 265 | else |
|
- | 266 | { |
|
- | 267 | min = eeprom_read_word(mineepadr); |
|
- | 268 | max = eeprom_read_word(maxeepadr); |
|
- | 269 | } |
|
- | 270 | ||
235 | // Farbablauf: rot > Violett > blau > tuerkis > gruen > gelb > |
271 | printf("ppm: %d / min: %d / max: %d\n",ppm,min,max); |
- | 272 | ||
- | 273 | ||
236 | 274 | setup = 0; |
|
237 | 275 | setupdly = SetDelay(3000); |
|
238 | colorState = 0; |
276 | ppmtodly = SetDelay(5000); |
239 | 277 | ||
240 | while (1) |
278 | while (1) |
241 | { |
279 | { |
242 | - | ||
243 | /* |
- | |
244 | #define step 128 |
- | |
245 | #define mul 2 |
- | |
246 | - | ||
247 | if ((ppm >= (step * 0) && (ppm < (step * 1))) ch0 = mul * ((ppm - (step * 0))); |
- | |
248 | if ((ppm >= (step * 1)) && (ppm < (step * 2))) ch1 = mul * ((ppm - (step * 1))); |
- | |
249 | if ((ppm >= (step * 2)) && (ppm < (step * 3))) ch0 = mul * ((step - 1) - (ppm - (step * 2))); |
- | |
250 | if ((ppm >= (step * 3)) && (ppm < (step * 4))) ch2 = mul * ((ppm - (step * 3))); |
- | |
251 | if ((ppm >= (step * 4)) && (ppm < (step * 5))) ch1 = mul * ((step - 1) - (ppm - (step * 4))); |
- | |
252 | if ((ppm >= (step * 5)) && (ppm < (step * 6))) ch0 = mul * ((ppm - (step * 5))); |
- | |
253 | if ((ppm >= (step * 6)) && (ppm < (step * 7))) ch2 = mul * ((step - 1) - (ppm - (step * 6))); |
- | |
254 | - | ||
255 | //printf("%d ",ppm); |
- | |
256 | */ |
- | |
257 | 280 | ||
258 | for (i=0; i<=255; i++) |
281 | if (ppm_new > 20) |
259 | { |
282 | { |
260 | switch(colorState) |
- | |
261 | { |
283 | PORTC clrbit ledred; |
262 | case 0: |
284 | ppm = GetPPM(); |
263 | ch0 = i; //fade in (ch0) red |
285 | ppmtodly = SetDelay(500); |
264 | nextcolorState = 2; |
- | |
265 | break; |
- | |
266 | - | ||
267 | case 2: |
- | |
268 | ch1 = i; //fade in (ch1) blue to get pure purple (red + blue) |
286 | if (lmax < ppm) lmax=ppm; |
269 | nextcolorState = 4; |
- | |
270 | break; |
287 | if (lmin > ppm) lmin=ppm; |
271 | 288 | } |
|
272 | case 4: |
- | |
273 | ch0 = 255 - i; //fade out (ch0) red to get pure blue |
- | |
274 | nextcolorState = 6; |
- | |
275 | break; |
289 | else |
276 | - | ||
277 | case 6: |
- | |
278 | ch2 = i; //fade in (ch2) green to get pure cyan (blue + green) |
290 | { |
279 | nextcolorState = 8; |
291 | PORTC setbit ledred; |
280 | break; |
292 | ppm = min; |
281 | - | ||
282 | case 8: |
- | |
283 | ch1 = 255 - i; //fade out (ch1) blue to get pure green |
- | |
284 | nextcolorState = 10; |
- | |
285 | break; |
293 | } |
286 | - | ||
287 | case 10: |
- | |
288 | ch0 = i; //fade in (ch0) red to get yellow pure (green + red) |
294 | |
289 | nextcolorState = 12; |
- | |
290 | break; |
295 | if (CheckDelay(ppmtodly)) |
291 | - | ||
292 | case 12: |
- | |
293 | ch2 = 255 - i; //fade out (ch2) green to get pure red |
296 | { |
294 | nextcolorState = 0; |
297 | ppmtodly = SetDelay(5000); |
295 | break; |
298 | ppm_new = 0; |
- | 299 | } |
|
- | 300 | ||
- | 301 | if ((ppm > 1600) && ((setup&1)==0)) setup++; |
|
- | 302 | if ((ppm < 1400) && ((setup&1)==1)) setup++; |
|
- | 303 | if (setup == 6) |
|
- | 304 | { |
|
- | 305 | PORTD setbit ledgreen; |
|
- | 306 | eeprom_write_word(mineepadr, lmin); |
|
- | 307 | eeprom_write_word(maxeepadr, lmax); |
|
- | 308 | min = lmin; |
|
- | 309 | max = lmax; |
|
- | 310 | setupdly = SetDelay(2000); |
|
- | 311 | } |
|
- | 312 | if (CheckDelay(setupdly)) |
|
- | 313 | { |
|
- | 314 | setup = 0; |
|
- | 315 | PORTD clrbit ledgreen; |
|
- | 316 | } |
|
- | 317 | ||
- | 318 | //printf("ppm: %d / min: %d / max: %d\n",ppm,lmin,lmax); |
|
- | 319 | ||
- | 320 | ||
- | 321 | /* |
|
- | 322 | // Farbablauf: rot > Violett > blau > tuerkis > gruen > gelb > |
|
- | 323 | if ((ppm >= (step * 0)) && (ppm < (step * 1))) |
|
- | 324 | { |
|
- | 325 | ch0 = mul * ((ppm - (step * 0))); //fade in red > red (red only) |
|
- | 326 | ch1 = 0; |
|
- | 327 | ch2 = 0; |
|
296 | } |
328 | } |
- | 329 | if ((ppm >= (step * 1)) && (ppm < (step * 2))) |
|
- | 330 | { |
|
- | 331 | ch0 = ((step-1) * mul); |
|
- | 332 | ch2 = mul * ((ppm - (step * 1))); //fade in blue > purple (red + blue) |
|
- | 333 | ch1 = 0; |
|
- | 334 | } |
|
297 | 335 | if ((ppm >= (step * 2)) && (ppm < (step * 3))) |
|
- | 336 | { |
|
298 | 337 | ch0 = mul * ((step - 1) - (ppm - (step * 2))); //fade out red > blue (blue only) |
|
- | 338 | ch2 = ((step-1) * mul); |
|
- | 339 | ch1 = 0; |
|
- | 340 | } |
|
- | 341 | if ((ppm >= (step * 3)) && (ppm < (step * 4))) |
|
- | 342 | { |
|
- | 343 | ch0 = 0; |
|
- | 344 | ch2 = ((step-1) * mul); |
|
- | 345 | ch1 = mul * ((ppm - (step * 3))); //fade in green > tuerkis (blue + green) |
|
- | 346 | } |
|
- | 347 | if ((ppm >= (step * 4)) && (ppm < (step * 5))) |
|
- | 348 | { |
|
- | 349 | ch0 = 0; |
|
- | 350 | ch2 = mul * ((step - 1) - (ppm - (step * 4))); //fade out blue > green (green only) |
|
- | 351 | ch1 = ((step-1) * mul); |
|
- | 352 | } |
|
- | 353 | if ((ppm >= (step * 5)) && (ppm < (step * 6))) |
|
- | 354 | { |
|
- | 355 | ch0 = mul * ((ppm - (step * 5))); //fade in red > yellow (green + red) |
|
- | 356 | ch2 = 0; |
|
- | 357 | ch1 = ((step-1) * mul); |
|
- | 358 | } |
|
- | 359 | if ((ppm >= (step * 6)) && (ppm < (step * 7))) |
|
- | 360 | { |
|
- | 361 | ch0 = ((step-1) * mul); |
|
- | 362 | ch2 = 0; |
|
- | 363 | ch1 = mul * ((step - 1) - (ppm - (step * 6))); //fade out green > red (red only) |
|
- | 364 | } |
|
- | 365 | if ((ppm >= (step * 7)) ) |
|
- | 366 | { |
|
- | 367 | ch0 = ((step-1) * mul); |
|
- | 368 | ch2 = 0; |
|
- | 369 | ch1 = 9; |
|
- | 370 | } |
|
299 | timer = SetDelay(5); //wait 10ms |
371 | */ |
300 | while (!CheckDelay(timer)); |
- | |
301 | } |
- | |
302 | - | ||
303 | colorState = nextcolorState; |
372 | |
304 | 373 | ||
305 | timer = SetDelay(3); //hold pure colors for additional 3ms |
374 | |
306 | while (!CheckDelay(timer)); |
375 | |
307 | 376 | ||
308 | 377 | ||
309 | } |
378 | } |
310 | 379 | ||
311 | 380 | ||
312 | } |
381 | } |
313 | 382 | ||
314 | 383 |