#include #include volatile static int r=10,g=998,b=998; volatile static char rgb=0; ISR(TIM0_COMPB_vect){ char hi=2; int low=998; char x1,x2,x3,x4,x5,x6,x7,x8; static char f; switch(rgb){ case 0: PORTB |=_BV(0); if((50 < ADCL) != (ADCL < 150)){ if(100 < ADCL){x1=4;x2=5;x3=1;x4=2;} else {x1=1;x2=0;x3=4;x4=3;} if(f==x1){ if(r > hi) r--; if(r==hi) f=x2; } if(f==x3){ if(r < low) r++; if(r==low) f=x4; } } break; case 1: PORTB |=_BV(1); if((50 < ADCL) != (ADCL < 150)){ if(100 < ADCL){x1=0;x2=1;x3=3;x4=4;x5=4;x6=5;x7=5;x8=6;} else {x1=3;x2=2;x3=0;x4=6;x5=5;x6=4;x7=4;x8=3;} if(f==x1 || f==x5){ if(g > hi) g--; if(g==hi){if(f==x1) f=x2; else f=x6;} } if(f==x3 || f==x7){ if(g < low) g++; if(g==low){if(f==x3) f=x4; else f=x8;} } } break; case 2: PORTB |=_BV(2); if((50 < ADCL) != (ADCL < 150)){ if(100 < ADCL){x1=2;x2=3;x3=6;x4=0;} else {x1=6;x2=5;x3=2;x4=1;} if(f==x1){ if(b > hi) b--; if(b==hi) f=x2; } if(f==x3){ if(b < low) b++; if(b==low) f=x4; } } break; } rgb++; if(rgb >= 3) rgb=0; } /////////////////////////////////////// /////////////////////////////////////// ISR(TIM0_COMPA_vect){ PORTB= (0xF8 & 0xF8); switch(rgb){ case 0: OCR0B =r; break; case 1: OCR0B =g; break; case 2: OCR0B =b; break; } TCCR0B = 0x00; TCNT0 = 0; TCCR0B = 0x01; } /////////////////////////////////////////// /////////////////////////////////////////// int main(){ DDRB = 0b11110111; PORTB =0b00000111; TCCR0A = 0x00; OCR0A = 1000; TIMSK0 = 0x06; ADMUX = 0b00000011; ADCSRA = 0b10000101; sei(); TCCR0B = 0x01; while(1){ ADCSRA = ADCSRA | 0b01000000; while(ADCSRA & 0b01000000); } return 0; }