 |
| PCBWay.com |
 |
| Welcome bonus bagi pendaftar akun pertama |
Selain mencetak PCB utama TEA6320 yang harus dikontrol mikrokontroller maka saya juga mencetak PCB untuk kontrolernya yang sekaligus panel penampil yang dilengkapi juga dengan rotary encoder sebagai pengaturannya, saya buat panel kontrol ini universal agar supaya bisa digunakan untuk proyek-proyek lainnya dengan menambah pinhead untuk semua pinout mikrokontrollernya dan tentunya layoutnya dual layer juga, dibawah ini saya sertakan skema dan layout yang sudah saya rancang.
 |
| Skema universal control panel |
 |
| Layout Universal Control Panel depan belakang |
Nah ketika PCB utama TEA6320 beserta PCB Control display telah selesai dibuat layoutnya dan juga telah selesai dicetak menjadi sebuah PCB di PCBWay maka seperti inilah hasilnya.
Setelah selesai dirakit maka tidak bisa langsung digunakan tanpa ada program yang bisa mengontrolnya, maka saya juga mempelajari datasheet IC TEA6320 untuk mengetahui cara mengontrol semua fungsi yang ada pada ic tersebut dan ternyata malahan diluaran sana sudah ada yang membuat library untuk Arduinonya yaitu situs http://rcl-radio.ru, dengan library Arduino tersebut kita bisa lebih mudah dalam membuat programnya, program untuk mengontrol IC TEA6320 ini saya personalisasikan sesuai keinginan dan saya tampilkan menu:
1. Volume pada display LCD 16X2 pada baris pertama ditampilkan tulisan VOLUME beserta nilai level antara 1 sampai 50 dan nilai penguatan antara - 31 sampai 30 berupa desibel (dB) sedangkan dibaris kedua menampilkan bar dan animasi speaker.
 |
| Tampilan Volume |
2. Bass pada display LCD 16X2 pada baris pertama ditampilkan tulisan BASS beserta nilai level antara 1 sampai 30 dan nilai penguatan antara - 15 sampai 15 berupa desibel (dB) sedangkan dibaris kedua menampilkan bar dan animasi nada.
 |
| Tampilan Bass |
3. Treble pada display LCD 16X2 pada baris pertama ditampilkan tulisan TRBL beserta nilai level antara 1 sampai 24 dan nilai penguatan antara - 12 sampai 12 berupa desibel (dB) sedangkan dibaris kedua menampilkan bar dan animasi nada.
 |
| Tampilan Treble |
4. Loudness yang otomatis dikontrol dikombinasi dengan pengaturan volume.
 |
| Tampilan Loudness |
5. Input selector 1 sampai 4 masukan stereo.
 |
| Tampilan pemilihan sumber Input |
6. Mute akan aktif saat switch pada rotary encoder ditekan lama.
 |
| Tampilan saat Mute aktif |
Untuk kode programnya silakan dilihat dibawah ini atau bisa juga di
Download pada tautan ini sekaligus library untuk header Arduinonya.
#include < Wire.h>
#include < MsTimer2.h>
#include < Encoder.h>
#include < EEPROM.h>
#include < TEA6320.h>
#include < liquidcrystal_i2c .h=""> // library LCD
#define MUTE 10
#define SW 4
TEA6320 tea;
Encoder myEnc( 3, 2 ); //CLK, DT encoder connection
LiquidCrystal_I2C lcd(0x27, 16, 2); // Set Alamat I2C LCD dan type LCD
byte a1[ 8 ] = { 0b00000, 0b11011, 0b11011, 0b11011, 0b11011, 0b11011, 0b11011, 0b00000 };
byte a2[ 8 ] = { 0b00000, 0b11000, 0b11000, 0b11000, 0b11000, 0b11000, 0b11000, 0b00000 };
byte a3[ 8 ] = { 0b00000, 0b00000, 0b00000, 0b11011, 0b11011, 0b00000, 0b00000, 0b00000 };
byte spk[ 8 ] = { 0b00000,
0b00001,
0b00011,
0b01111,
0b01111,
0b00011,
0b00001,
0b00000
};
byte spkOn1[ 8 ] = { 0b00000,
0b00000,
0b01000,
0b00100,
0b00100,
0b01000,
0b00000,
0b00000
};
byte spkOn2[ 8 ] = { 0b00100,
0b00010,
0b00001,
0b00001,
0b00001,
0b00001,
0b00010,
0b00100
};
byte tone1[ 8 ] = { 0b11100,
0b11110,
0b01000,
0b00100,
0b00010,
0b01110,
0b11110,
0b01100
};
byte tone2[ 8 ] = { 0b00010,
0b00011,
0b00010,
0b01110,
0b11110,
0b01100,
0b00000,
0b00000
};
unsigned long newPosition, time, oldPosition = - 999;
int menu, w, vol, loud, vol_d, z, bass, bass_d, treb, treb_d, in , mute, m;
// constants won't change. They're used here to set pin numbers:
//const int BUTTON_PIN = 7; // the number of the pushbutton pin
const int SHORT_PRESS_TIME = 500; // 1000 milliseconds
const int LONG_PRESS_TIME = 500; // 1000 milliseconds
// Variables will change:
int lastState = HIGH; // the previous state from the input pin
int currentState; // the current reading from the input pin
unsigned long pressedTime = 0;
unsigned long releasedTime = 0;
bool gantian;
void setup( ) {
Serial.begin( 9600 );
Wire.begin( );
//lcd.begin( 16, 2 );
lcd.begin();
lcd.backlight();
lcd.createChar( 0, a1);
lcd.createChar( 1, a2 );
lcd.createChar( 2, a3 );
lcd.createChar( 3, spk );
lcd.createChar( 4, spkOn1 );
lcd.createChar( 5, spkOn2 );
lcd.createChar( 6, tone1 );
lcd.createChar( 7, tone2 );
pinMode( SW, INPUT_PULLUP); // ENCODER BUTTON
pinMode( MUTE, INPUT_PULLUP ); // MUTE
MsTimer2::set( 1, to_Timer );
MsTimer2::start();
vol = EEPROM.read( 0 ) - 31;
bass = EEPROM.read( 1 ) - 10;
treb = EEPROM.read( 2 ) - 8;
in = EEPROM.read( 7 );
loud = EEPROM.read ( 9 );
for ( z = 0 ; z <= 3; z++ ) {
tea.setBallance( z, 0 );
}
audio ( );
lcd.setCursor( 1, 0);
lcd.print("-= WELCOME =-");
lcd.setCursor( 0, 1);
lcd.print("> FAREED READ <");
delay(2000);
}
void to_Timer ( ) {
newPosition = myEnc.read ( ) / 4 ;
}
void loop ( ) {
// read the state of the switch/button:
currentState = digitalRead(SW);
if (lastState == HIGH && currentState == LOW) // button is pressed
pressedTime = millis();
else if (lastState == LOW && currentState == HIGH) { // button is released
releasedTime = millis();
long pressDuration = releasedTime - pressedTime;
if ( pressDuration < SHORT_PRESS_TIME ) {
menu ++; // menu
cl( );
myEnc.write ( 0 );
time = millis ( );
w = 1;
if ( menu > 4 ) {
menu = 0 ;
}
Serial.println("A short press is detected");
}
if ( pressDuration > LONG_PRESS_TIME ) {
mute++; // mute
if ( mute > 1 ) {
mute = 0 ;
}
audio ( ) ;
cl ( ) ;
}
if ( mute == 1 ) {
m = 1 ; // mute
lcd.setCursor( 12, 0);
lcd.print("MUTE");
lcd.setCursor( 0, 0);
lcd.print( "VOLUME ") ;
lcd.print( "0") ;
lcd.setCursor( 1, 1);
lcd.print("x");
lcd.setCursor( 0, 1);
lcd.write(( uint8_t ) 3);
for ( z = 3 ; z <= 15; z++ ) {
lcd.setCursor( z , 1);
lcd.write(( uint8_t ) 2);
}
menu = 100 ;
}
if ( mute == 0 && m == 1 ) {
cl ( );
menu = 0 ;
m = 0 ;
Serial.println("A long press is detected");
}
}
// save the the last state
lastState = currentState;
/////////////////////////////////////// Volume -31...20 dB // ////////////////////////////////////
if ( menu == 0 ) {
if ( newPosition != oldPosition ) {
oldPosition = newPosition;
vol = vol + newPosition;
myEnc.write ( 0 );
newPosition = 0;
lcd.clear( );
time = millis ( );
w = 1 ;
if ( vol > 20 ) {
vol = 20 ;
}
if ( vol < - 30 ) {
vol = - 30 ;
}
audio ( ) ;
}
lcd.setCursor( 7 , 0 );
lcd.print( vol + 30 );
lcd.setCursor( 0 , 0 );
lcd.print( "VOLUME" );
lcd.setCursor( 11 , 0 );
lcd.print( vol ) ;
lcd.print( "dB" ) ;
vol_d = ( vol + 30 ) / 2;
for ( z = 14 ; z >= (vol_d / 2); z-- ) {
lcd.setCursor( z + 4, 1);
lcd.write(( uint8_t ) 2);
}
if ( vol_d >= 0 ) {
for ( z = 0 ; z <= vol_d; z++ ) {
lcd.setCursor ((z / 2) + 3, 1 ) ;
lcd.write ((uint8_t) 0 ) ;
}
}
if ( ( vol_d ) % 2 == 0 ) {
lcd.setCursor( (z / 2 ) + 3, 1);
lcd.write(( uint8_t ) 1);
}
static uint16_t lsRn;
uint16_t Tmr = millis();
if ((Tmr - lsRn) > 500 )
{
lsRn = Tmr;
gantian = !gantian;
if (gantian == 1) {
lcd.setCursor( 1, 1);
lcd.write(( uint8_t ) 4);
}
else {
lcd.setCursor( 1, 1);
lcd.write(( uint8_t ) 5);
}
lcd.setCursor( 0, 1);
lcd.write(( uint8_t ) 3);
}
}
///////////////////////////////////////////////// ////////////////////////////////////////////////// ////
/////////////////////// indication bass tone -15...15 dB ///////////////// //
if ( menu == 1 ) {
if ( newPosition != oldPosition ) {
oldPosition = newPosition;
bass = bass + newPosition;
myEnc.write ( 0 );
newPosition = 0;
lcd.clear();
time = millis();
w = 1 ;
if ( bass > 10 ) {
bass = 10 ;
}
if ( bass < - 10 ) {
bass = - 10 ;
}
audio ( ) ;
}
lcd. setCursor ( 0, 0 ) ;
lcd. print ( "BASS " ) ;
lcd.print( bass + 10 );
lcd. setCursor ( 9 , 0 ) ;
lcd. print ( ( float ) bass * 1.5 , 1 ) ;
lcd. print ( "dB" ) ;
bass_d = bass / 2 + 5 ;
if ( bass_d >= 0 ) {
for ( z = 2 ; z <= bass_d; z++ ) {
lcd.setCursor ( z, 1 );
lcd.write ( ( uint8_t ) 0 ) ;
}
for ( z = bass_d ; z <= 8; z++ ) {
lcd.setCursor ( z + 2, 1 );
lcd.write(( uint8_t ) 2);
}
}
static uint16_t lsRn;
uint16_t Tmr = millis();
if ((Tmr - lsRn) > 600 )
{
lsRn = Tmr;
gantian = !gantian;
if (gantian == 1) {
lcd.setCursor( 0, 1);
lcd.write(( uint8_t ) 6);
}
else {
lcd.setCursor( 0, 1);
lcd.write(( uint8_t ) 7);
}
}
}
/////////////////////////////////////////////// ///////////////////////////////////////
/////////////////////// indication treble tone -12...12 dB ////////////////// //
if ( menu == 2 ) {
if ( newPosition != oldPosition ) {
oldPosition = newPosition;
treb = treb + newPosition;
myEnc.write( 0 );
newPosition = 0;
lcd.clear();
time = millis();
w = 1;
if ( treb > 8 ) {
treb = 8;
}
if ( treb < - 8 ) {
treb = - 8;
}
audio();
}
lcd.setCursor( 0 , 0 );
lcd.print("TRBL ");
lcd.print( treb + 8 );
lcd.setCursor( 9, 0 );
lcd.print((float)treb * 1.5, 1);
lcd.print("dB");
treb_d = treb / 2 + 4;
if ( treb_d >= 0 ) {
for ( z = 2 ; z <= treb_d; z++ ) {
lcd.setCursor ( z, 1 );
lcd.write ( ( uint8_t ) 0 ) ;
}
for ( z = treb_d ; z <= 7; z++ ) {
lcd.setCursor ( z + 2, 1 );
lcd.write(( uint8_t ) 2);
}
}
static uint16_t lsRn;
uint16_t Tmr = millis();
if ((Tmr - lsRn) > 600 )
{
lsRn = Tmr;
gantian = !gantian;
if (gantian == 1) {
lcd.setCursor( 0, 1);
lcd.write(( uint8_t ) 6);
}
else {
lcd.setCursor( 0, 1);
lcd.write(( uint8_t ) 7);
}
}
}
if ( menu == 3 ) {
if ( newPosition != oldPosition ) {
oldPosition = newPosition;
loud = loud + newPosition;
myEnc.write( 0 );
newPosition = 0;
lcd.clear ( );
time = millis ( );
w = 1;
if ( loud > 1 ) {
loud = 0;
}
if ( loud < 0 ) {
loud = 1;
}
}
lcd.setCursor(2, 0);
lcd.print("-=LOUDNESS=-");
if (loud == 0) {
lcd.setCursor(5, 1);
lcd.print(">> ON");
}
else {
lcd.setCursor(5, 1);
lcd.print("OFF <<");
}
audio ( );
}
if ( menu == 4 ) {
if ( newPosition != oldPosition ) {
oldPosition = newPosition;
in = in + newPosition;
myEnc.write( 0 );
newPosition = 0;
lcd.clear ( );
time = millis ( );
w = 1;
if ( in > 3 ) {
in = 0;
}
if ( in < 0 ) {
in = 3;
}
}
lcd.setCursor(0, 0);
lcd.print("Source Selector:");
lcd.setCursor(4, 1);
lcd.print("INPUT ");
lcd.print(in + 1);
audio ( );
}
if ( millis() - time > 10000 && w == 1 ) {
EEPROM.update( 0, vol + 31 );
EEPROM.update( 1, bass + 10);
EEPROM.update( 2, bass + 8 );
EEPROM.update( 7, in );
EEPROM.update( 9, loud );
cl ( );
menu = 0;
w = 0;
}
}
void cl ( ) {
//delay ( 50 ) ;
lcd.clear ( ) ;
}
void audio ( ) {
tea.setVol_Loud( vol, loud ); // vol = -31...+20 dB = int -31...20 | loud = 0 off, 1 on
tea.setBass( bass ); //-15...+15 dB = int -10...10
tea.setTreb( treb ); //-12...+12 dB = int -8...8
tea.setInput( in, mute ); //int 0...3 | mute
}