const int CE=19; const int DI=18; const int CL=17; const int VOLa=2; const int VOLb=4; const int SELECT=16; const int MUTE=6; const int BASTREa=3; const int BASTREb=5; const int BT=7; const int SEL4=11; // Shift Register I/O const int SCLK=8; const int SDATA=9; const int SSTRB=10; byte addr=0x82; byte bass=0; byte treble=5; byte treb=0; byte volume=50; byte select=0; byte igain=5; volatile byte update=LOW; byte released = HIGH; byte sreleased = HIGH; byte muterlsd=HIGH; byte s1; byte s2; byte s3; void setup(){ pinMode(CE,OUTPUT); //CE pinMode(DI,OUTPUT); //DI pinMode(CL,OUTPUT); pinMode(SCLK,OUTPUT); //CE pinMode(SDATA,OUTPUT); //DI pinMode(SSTRB,OUTPUT); pinMode(SEL4,OUTPUT); digitalWrite(VOLa,HIGH); digitalWrite(VOLb,HIGH); digitalWrite(SELECT,HIGH); digitalWrite(MUTE,HIGH); digitalWrite(BASTREa,HIGH); digitalWrite(BASTREb,HIGH); digitalWrite(BT,HIGH); attachInterrupt(1,bastrecontrol,HIGH); attachInterrupt(0,volumecontrol,CHANGE); s1=0x00; s2=0x00; s3=0x00; } void loop(){ //delay(1000); CCB_Command(0); xferIO(); delay(2000); update=HIGH; while(1){ inselector(); // service selector switch trebleDisp(); // service bass/treble switch MuteCont(); // service mute switch if(update==HIGH){ update=LOW; CCB_Command(0); configLED(); xferIO(); } } } void CCB_Command(byte ch){ byte temp; digitalWrite(CL,LOW); digitalWrite(CE,HIGH); // Start with CE High digitalWrite(CE,LOW); // Now ready to send address shiftOut(DI,CL,LSBFIRST,addr); digitalWrite(CE,HIGH); // build next byte, select and input gain // each are 4 bits wide assembled together // to form an 8 bit data temp=igain<<4; temp += select; shiftOut(DI,CL,LSBFIRST,temp); // send volume control setting if(digitalRead(MUTE)==HIGH) shiftOut(DI,CL,LSBFIRST,volume); else shiftOut(DI,CL,LSBFIRST,60); // volume muted when pressed // Bass (lower 4 bits) and treble control temp=bass<<4; temp+=treb; shiftOut(DI,CL,LSBFIRST,temp); // Bass (upper 2 bits) & Channel selection temp=bass>>4; if(ch==0) temp+=0x0c; if(ch==1) temp+=0x04; //right channel only if(ch==2) temp+=0x08; //left channel only shiftOut(DI,CL,LSBFIRST,temp); digitalWrite(CE,LOW); } /* Bass and Treble Control */ void bastrecontrol(void){ //long int hintay=0; // Delay Muna //while(hintay<200000) hintay++; // Activate update request update=HIGH; if(digitalRead(BT)==HIGH){ //Bass Control if((digitalRead(BASTREa)==HIGH)&& (digitalRead(BASTREb)==LOW)) if(bass<10) bass++; if((digitalRead(BASTREa)==HIGH)&& (digitalRead(BASTREb)==HIGH)) if(bass>0) bass--; if((digitalRead(BASTREa)==LOW)&& (digitalRead(BASTREb)==HIGH)) if(bass<10) bass++; if((digitalRead(BASTREa)==LOW)&& (digitalRead(BASTREb)==LOW)) if(bass>0) bass--; } else { //Treble Control if((digitalRead(BASTREa)==HIGH)&& (digitalRead(BASTREb)==LOW)) if(treble<10) treble++; if((digitalRead(BASTREa)==HIGH)&& (digitalRead(BASTREb)==HIGH)) if(treble>0) treble--; if((digitalRead(BASTREa)==LOW)&& (digitalRead(BASTREb)==HIGH)) if(treble<10) treble++; if((digitalRead(BASTREa)==LOW)&& (digitalRead(BASTREb)==LOW)) if(treble>0) treble--; // Compute for IC ready trebele spec if(treble>=5) treb=treble-5; else treb=13-treble; } } /* Volume Control Interrupt Routine */ void volumecontrol(void){ //int hintay=0; // Delay Muna //while(hintay<5000) hintay++; if((digitalRead(VOLa)==HIGH)&& (digitalRead(VOLb)==LOW)) if(volume>0) volume--; if((digitalRead(VOLa)==HIGH)&& (digitalRead(VOLb)==HIGH)) if(volume< 0x50) volume++; if((digitalRead(VOLa)==LOW)&& (digitalRead(VOLb)==HIGH)) if(volume>0) volume--; if((digitalRead(VOLa)==LOW)&& (digitalRead(VOLb)==LOW)) if(volume< 0x50) volume++; // Activate update request update=HIGH; } /* Input Selector */ void inselector(void){ if(sreleased==HIGH){ if(digitalRead(SELECT)==HIGH) return; sreleased=LOW; delay(250); select++; if(select>3) select=0; update=HIGH; } else if(digitalRead(SELECT)==HIGH) sreleased=HIGH; } /* Trebel Mode */ void trebleDisp(void){ if(released==HIGH){ if(digitalRead(BT)==HIGH) return; released=LOW; delay(250); update=HIGH; } else if(digitalRead(BT)==HIGH){ released=HIGH; update=HIGH; } } /* Mute Control */ /* Trebel Mode */ void MuteCont(void){ if(muterlsd==HIGH){ if(digitalRead(MUTE)==HIGH) return; muterlsd=LOW; delay(250); update=HIGH; } else if(digitalRead(MUTE)==HIGH){ muterlsd=HIGH; update=HIGH; } } /* Refresh LED Display */ /* Shift Register I/O */ // Clock = rising edge // Strobe = Normally Low void xferIO(void){ digitalWrite(SCLK,LOW); digitalWrite(SSTRB,LOW); shiftOut(SDATA,SCLK,MSBFIRST,s3); shiftOut(SDATA,SCLK,MSBFIRST,s2); shiftOut(SDATA,SCLK,MSBFIRST,s1); digitalWrite(SSTRB,HIGH); digitalWrite(SSTRB,LOW); } void configLED(void){ int scratch; int vol; int bassortreb; if(digitalRead(BT)==HIGH) bassortreb=bass; else bassortreb=treble; // Process Bit for bass/treble control if(bassortreb<8){ s1=1; s1=s1<=60)){ s2|=0xF8; s3|=0x1F; s2 &= 0xF7; } if((volume<60) & (volume>=45)){ s2|=0xF8; s3|=0x1F; s2 &= 0xE7; } if((volume<45) & (volume>=30)){ s2|=0xF8; s3|=0x1F; s2 &= 0xC7; } if((volume<30) & (volume>=21)){ s2|=0xF8; s3|=0x1F; s2 &= 0x87; } if((volume<21) & (volume>=15)){ s2|=0xF8; s3|=0x1F; s2 &= 0x07; } if((volume<15) & (volume>=10)){ s2&=0x07; s3|=0x1F; s3 &= 0xFE; } if((volume<10) & (volume>=7)){ s2&=0x07; s3|=0x1F; s3 &= 0xFC; } if((volume<7) & (volume>=3)){ s2&=0x07; s3|=0x1F; s3 &= 0xF8; } if((volume<3) & (volume>0)){ s2&=0x07; s3|=0x1F; s3 &= 0xF0; } if(volume==0){ s2&=0x07; s3|=0x1F; s3 &= 0xE0; } /* // If volume = 0 (max volume) all vol LEDs are ON if(volume==0){ s2&=0x07; s3&=0xE0; } else{ if(vol<4){ s2&=0x07; s3 =0xF0; s3=s3>>vol; } else{ vol=vol-4; s3=0x1F; scratch=0x00; while(vol>0){ vol--; scratch=scratch>>1; scratch |= 0x80; } scratch &= 0xF8; s2 &= 0x07; s2 |= scratch; } } */ // Process Selector LED display if(select==3){ digitalWrite(SEL4,LOW); s3 |=0xE0; } else { digitalWrite(SEL4,HIGH); s3 |= 0xE0; if(select==2) s3&= 0x7F; if(select==1) s3&=0xBF; if(select==0) s3&= 0xDF; } }