Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 8

/*+++++++++++++++++++++++++++++++++++++++++++++++++++

Nama : Amron Zamzami


NIM : 16.6.20-201.C.0397
Program Studi : Teknik Elektro STT WIWOROTOMO PURWOKERTO
Skripsi : Pengendalian Audio Prosesor IC PT2313 dengan Arduino Uno dan
Bluetooth

+++++++++++++++++++++++++++++++++++++++++++++++++++*/
#include <Wire.h>
#include <LiquidCrystal.h>
#include <PT2313.h>
#include <String.h>
LiquidCrystal lcd(8,9,4,5,6,7);

#include <SoftwareSerial.h>
#define RxD 0
#define TxD 1
char recvChar;
SoftwareSerial blueToothSerial(RxD,TxD);

int keypad_pin =A0;


int keypad_value = 0;
int keypad_value_old = 0;
char btn_push;
int ini,sor,vol,gan,lod,bas,tre,bal;
byte mainMenuPage = 1;
byte mainMenuPageOld = 1;
byte mainMenuTotal = 7;
unsigned char menu;
PT2313 audioChip;

void setup()
{
delay(5000);
lcd.begin(16,2); //Initialize a 2x16 type LCD
audioChip.initialize(1,true);
audioChip.source(1); //select your source 0...3
audioChip.volume(10); //Vol 0...62 : 63=muted
audioChip.gain(3); //gain 0...11.27 db
audioChip.loudness(true); //true or false
audioChip.bass(7); //bass -7...+7
audioChip.treble(7); //treble -7...+7
audioChip.balance(0); //-31...+31

lcd.clear();
lcd.setCursor(1,0);
lcd.print("STT WIWOROTOMO");
lcd.setCursor(1,1);
lcd.print("Amron Zamzami");
delay(1000);
audioChip.initialize(1,true); //source 1,mute on
lcd.clear();
lcd.setCursor(1,0);
lcd.print("initialize.");
delay(1000);
lcd.setCursor(1,0);
lcd.print("initialize..");
delay(1000);
lcd.setCursor(1,0);
lcd.print("initialize...");
delay(1000);
lcd.setCursor(1,0);
lcd.print("initialize....");
delay(1000);
lcd.setCursor(1,0);
lcd.print("initialize.....");
delay(2000);

Serial.begin(9600);
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
blueToothSerial.begin(9600);
Wire.begin(); // i2c
MainMenuDisplay();
delay(1000);
}
void loop()
{
btn_push = ReadKeypad();
MainMenuBtn();
if(btn_push == 'S') //enter selected menu
{
WaitBtnRelease();
switch (mainMenuPage)
{
case 1:
MenuA();
break;
case 2:
MenuB();
break;
case 3:
MenuC();
break;
case 4:
MenuD();
break;
case 5:
MenuE();
break;
case 6:
MenuF();
break;
case 7:
MenuG();
break;
}
MainMenuDisplay();
WaitBtnRelease();
}
delay(10);
}//--------------- End of loop() loop ---------------------

void MenuA()
{
while(ReadKeypad()!= 'S')
{
void loop();
delay(50);
if ((keypad_value<100) || (recvChar == 'R'))
if (sor ==3)
sor =3;
else
sor++;
delay(50);

if (((keypad_value >400)&&(keypad_value <600)) || (recvChar == 'L'))


//Insert Task for Menu A here
if (sor ==1)
sor !=4;
else
sor--;
audioChip.source(sor);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Source :");
lcd.setCursor(9,0);
lcd.print(String(sor));
delay(50);
}}

void MenuB()
{
while(ReadKeypad()!= 'S')
{
void loop();
delay(50);
if ((keypad_value<100) || (recvChar == 'R'))
if (vol ==62)
vol =62;
else
vol++;
delay(50);

if (((keypad_value >400)&&(keypad_value <600)) || (recvChar == 'L'))


//Insert Task for Menu A here
if (vol ==0)
vol !=62;
else
vol--;
audioChip.volume(vol);
lcd.setCursor(9,0);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Volume :");
lcd.print(String(vol));
delay(50);
}}

void MenuC()
{
while(ReadKeypad()!= 'S')
{
void loop();
delay(50);
if ((keypad_value<100) || (recvChar == 'R'))
if (gan ==07)
gan =07;
else
gan++;
delay(50);

if (((keypad_value >400)&&(keypad_value <600)) || (recvChar == 'L'))


//Insert Task for Menu B here
if (gan ==-7)
gan !=+8;
else
gan--;
audioChip.gain(gan);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Gain :");
lcd.setCursor(9,0);
lcd.print(String(gan));
delay(50);
}}

void MenuD()
{
while(ReadKeypad()!= 'S')
{
void loop();
delay(50);
if ((keypad_value<100) || (recvChar == 'R'))
if (lod ==1)
lod =1;
else
lod++;
delay(50);

if (((keypad_value >400)&&(keypad_value <600)) || (recvChar == 'L'))


//Insert Task for Menu D here
if (lod ==0)
lod !=0;
else
lod--;
audioChip.loudness(lod);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Loudness :");
lcd.setCursor(10,0);
lcd.print(String(lod));
delay(50);
}}

void MenuE()
{
while(ReadKeypad()!= 'S')
{
void loop();
delay(50);
if ((keypad_value<100) || (recvChar == 'R'))
if (bas ==07)
bas =07;
else
bas++;
delay(50);

if (((keypad_value >400)&&(keypad_value <600)) || (recvChar == 'L'))


//Insert Task for Menu B here
if (bas ==-7)
bas !=+8;
else
bas--;
audioChip.bass(bas);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Bass :");
lcd.setCursor(9,0);
lcd.print(String(bas));
delay(50);
}}

void MenuF()
{
while (ReadKeypad()!= 'S')
{
void loop();
delay(50);
if ((keypad_value<100) || (recvChar == 'R'))
if (tre ==7)
tre =7;
else
tre++;
delay(50);

if (((keypad_value >400)&&(keypad_value <600)) || (recvChar == 'L'))


if (tre ==-7)
tre !=+8;
else
tre--;
audioChip.treble(tre);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Treble :");
lcd.setCursor(9,0);
lcd.print(String(tre));
delay(50);
}}

void MenuG()
{
while (ReadKeypad()!= 'S')
{
void loop();
delay(50);
if ((keypad_value<100)|| (recvChar == 'R'))
if (bal ==31)
bal =31;
else
bal++;
delay(50);
if (((keypad_value >400)&&(keypad_value <600)) || (recvChar == 'L'))
//Insert Task for Menu D here
if (bal ==-31)
bal !=+32;
else
bal--;
audioChip.balance(bal);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Balance :");
lcd.setCursor(9,0);
lcd.print(String(bal));
delay(50);
}}

void MainMenuDisplay()
{
lcd.clear();
lcd.setCursor(0,0);
switch (mainMenuPage)
{
case 1:
lcd.print("1. Source");
break;
case 2:
lcd.print("2. Volume");
break;
case 3:
lcd.print("3. Gain");
break;
case 4:
lcd.print("4. Loudness");
break;
case 5:
lcd.print("5. Bass");
break;
case 6:
lcd.print("6. Treble");
break;
case 7:
lcd.print("7. Balance");
break;
}}

void MainMenuBtn()
{
WaitBtnRelease();
if(btn_push == 'U')
{
mainMenuPage++;
if(mainMenuPage > mainMenuTotal)
mainMenuPage = 1;
}
else if(btn_push == 'D')
{
mainMenuPage--;
if(mainMenuPage == 0)
mainMenuPage = mainMenuTotal;
}
if(mainMenuPage != mainMenuPageOld) //only update display when
page change
{
MainMenuDisplay();
mainMenuPageOld = mainMenuPage;
}}

char ReadKeypad()
{
keypad_value = analogRead(keypad_pin);
//lcd.clear();
//lcd.setCursor(4,1);
//lcd.print(String(keypad_value));
if(keypad_value < 100)
return 'R';
else if(keypad_value < 200)
return 'U';
else if(keypad_value < 400)
return 'D';
else if(keypad_value < 600)
return 'L';
else if(keypad_value < 800)
return 'S';
//else
// return 'N';

recvChar = blueToothSerial.read();
Serial.print(recvChar);

if(recvChar == 'U')
return 'U';
else if(recvChar == 'D')
return 'D';
else if(recvChar == 'L')
return 'L';
else if(recvChar == 'R')
return 'R';
else if(recvChar == 'S')
return 'S';
else
return 'N';
}
void WaitBtnRelease()
{
while( analogRead(keypad_pin) < 800){}
}

/*void bluetooth()
{
{ if(blueToothSerial.available()) //bluetooth
{
recvChar = blueToothSerial.read();
Serial.print(recvChar);

if(recvChar == 'U') keypad_value =142;


if(recvChar == 'D') keypad_value =326;
if(recvChar == 'L') keypad_value =503;
if(recvChar == 'R') keypad_value =0;
if(recvChar == 'S') keypad_value =741;

//lcd.setCursor(0,1);
//lcd.println(recvChar);
//delay(500);
delay(50);
}}}*/

/* Keypad button analog Value


no button pressed 1023
select 741
left 503
down 326
up 142
right 0
*/
/*select 721
left 481
right 0
up 133
down 309
*/

You might also like