// LGT8F328
// сетки
#define SETKA_0 2
#define SETKA_1 3
// аноды
#define P1 4
#define P2 5
#define P3 6
#define P4 7
#define P5 8
#define P6 10
#define P7 11
#define P8 12
#define P9 13
#define P10 A0
#define P11 A1
#define P12 A2
#define P13 A3
#define P14 A4
// входы аудио
#define AN_R A6
#define AN_L A7
#define LOW_IN 2
#define HIGH_IN 50
byte h;
int r_in,l_in,r,l;
int ur_l,urr_l,ur_r,urr_r;
void setup(){
Serial.begin(9600);
noInterrupts();
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
TCCR1A = (1 << COM1A1)|(1 << WGM11);
TCCR1B = (1 << WGM13)|(1 << WGM12)|(1 << CS10);
DDRB = 1 << DDB1; // OUTPUT PWM (OCR1A)
OCR1A = 15;
ICR1 = 40;
/////
TCCR2A = 0;
TCCR2B = 0;
TCNT2 = 0;
OCR2A = 77;
TCCR2A |= (1 << WGM21);
TCCR2B |= (1 << CS22) | (1 << CS21) | (1 << CS20);
TIMSK2 |= (1 << OCIE2A);
interrupts();
pinMode(2,OUTPUT);pinMode(3,OUTPUT);pinMode(P1,OUTPUT);pinMode(P1,OUTPUT);pinMode(P3,OUTPUT);pinMode(P4,OUTPUT);pinMode(P5,OUTPUT);pinMode(P6,OUTPUT);pinMode(P7,OUTPUT);
pinMode(P8,OUTPUT);pinMode(P9,OUTPUT);pinMode(P10,OUTPUT);pinMode(P11,OUTPUT);pinMode(P12,OUTPUT);pinMode(P13,OUTPUT);pinMode(P14,OUTPUT);
pinMode(AN_R,INPUT);
pinMode(AN_L,INPUT);
analogReadResolution(8);
analogReference(INTERNAL1V024);
}
void loop(){
r_in = map(analogRead(AN_R), LOW_IN,HIGH_IN, 0, 14);
l_in = map(analogRead(AN_L), LOW_IN,HIGH_IN, 0, 14);
r = constrain(r_in, 0, 14);
l = constrain(l_in, 0, 14);
urr_l = l;
urr_r = r;
if(urr_l<ur_l){ur_l=ur_l-1;}else{ur_l = l;}
if(urr_r<ur_r){ur_r=ur_r-1;}else{ur_r = r;}
delay(50);
}
ISR(TIMER2_COMPA_vect){
switch(h){
case 0: segm(ur_l);ch(SETKA_0,0);ch(SETKA_1,1);break;
case 1: segm(ur_r);ch(SETKA_0,1);ch(SETKA_1,0);break;
}
h++;if(h>1){h=0;}
}
void segm(int a){
switch(a){
case 0: ch(P1,1);ch(P2,1);ch(P3,1);ch(P4,1);ch(P5,1);ch(P6,1);ch(P7,1);ch(P8,1);ch(P9,1);ch(P10,1);ch(P11,1);ch(P12,1);ch(P13,1);ch(P14,1);break;
case 1: ch(P1,0);ch(P2,1);ch(P3,1);ch(P4,1);ch(P5,1);ch(P6,1);ch(P7,1);ch(P8,1);ch(P9,1);ch(P10,1);ch(P11,1);ch(P12,1);ch(P13,1);ch(P14,1);break;
case 2: ch(P1,0);ch(P2,0);ch(P3,1);ch(P4,1);ch(P5,1);ch(P6,1);ch(P7,1);ch(P8,1);ch(P9,1);ch(P10,1);ch(P11,1);ch(P12,1);ch(P13,1);ch(P14,1);break;
case 3: ch(P1,0);ch(P2,0);ch(P3,0);ch(P4,1);ch(P5,1);ch(P6,1);ch(P7,1);ch(P8,1);ch(P9,1);ch(P10,1);ch(P11,1);ch(P12,1);ch(P13,1);ch(P14,1);break;
case 4: ch(P1,0);ch(P2,0);ch(P3,0);ch(P4,0);ch(P5,1);ch(P6,1);ch(P7,1);ch(P8,1);ch(P9,1);ch(P10,1);ch(P11,1);ch(P12,1);ch(P13,1);ch(P14,1);break;
case 5: ch(P1,0);ch(P2,0);ch(P3,0);ch(P4,0);ch(P5,0);ch(P6,1);ch(P7,1);ch(P8,1);ch(P9,1);ch(P10,1);ch(P11,1);ch(P12,1);ch(P13,1);ch(P14,1);break;
case 6: ch(P1,0);ch(P2,0);ch(P3,0);ch(P4,0);ch(P5,0);ch(P6,0);ch(P7,1);ch(P8,1);ch(P9,1);ch(P10,1);ch(P11,1);ch(P12,1);ch(P13,1);ch(P14,1);break;
case 7: ch(P1,0);ch(P2,0);ch(P3,0);ch(P4,0);ch(P5,0);ch(P6,0);ch(P7,0);ch(P8,1);ch(P9,1);ch(P10,1);ch(P11,1);ch(P12,1);ch(P13,1);ch(P14,1);break;
case 8: ch(P1,0);ch(P2,0);ch(P3,0);ch(P4,0);ch(P5,0);ch(P6,0);ch(P7,0);ch(P8,0);ch(P9,1);ch(P10,1);ch(P11,1);ch(P12,1);ch(P13,1);ch(P14,1);break;
case 9: ch(P1,0);ch(P2,0);ch(P3,0);ch(P4,0);ch(P5,0);ch(P6,0);ch(P7,0);ch(P8,0);ch(P9,0);ch(P10,1);ch(P11,1);ch(P12,1);ch(P13,1);ch(P14,1);break;
case 10: ch(P1,0);ch(P2,0);ch(P3,0);ch(P4,0);ch(P5,0);ch(P6,0);ch(P7,0);ch(P8,0);ch(P9,0);ch(P10,0);ch(P11,1);ch(P12,1);ch(P13,1);ch(P14,1);break;
case 11: ch(P1,0);ch(P2,0);ch(P3,0);ch(P4,0);ch(P5,0);ch(P6,0);ch(P7,0);ch(P8,0);ch(P9,0);ch(P10,0);ch(P11,0);ch(P12,1);ch(P13,1);ch(P14,1);break;
case 12: ch(P1,0);ch(P2,0);ch(P3,0);ch(P4,0);ch(P5,0);ch(P6,0);ch(P7,0);ch(P8,0);ch(P9,0);ch(P10,0);ch(P11,0);ch(P12,0);ch(P13,1);ch(P14,1);break;
case 13: ch(P1,0);ch(P2,0);ch(P3,0);ch(P4,0);ch(P5,0);ch(P6,0);ch(P7,0);ch(P8,0);ch(P9,0);ch(P10,0);ch(P11,0);ch(P12,0);ch(P13,0);ch(P14,1);break;
case 14: ch(P1,0);ch(P2,0);ch(P3,0);ch(P4,0);ch(P5,0);ch(P6,0);ch(P7,0);ch(P8,0);ch(P9,0);ch(P10,0);ch(P11,0);ch(P12,0);ch(P13,0);ch(P14,0);break;
}
}
void ch(int pin, int logic){digitalWrite(pin, logic);}