#include <IRremote.h>
#include <Wire.h>
#include <LiquidCrystal.h>
#include <EEPROM.h>
#define PT2323_address 0b10010100
#define PT2322_address 0b10001000
#define LcdBacklight A1 // Anoda LCD
#define btn_delay 50
IRrecv irrecv(A0);
decode_results results;
/*
// IR HEX code
#define ir_power 0xFF02FD // IR power ON/OFF
#define ir_mute 0xFF48B7 // IR mute
#define ir_in 0xFFB847 // IR input select
#define ir_vol_i 0xFF30CF // IR vol++
#define ir_vol_d 0xFF18E7 // IR vol--
/*
#define ir_bass_i 0x807F8A75 // IR bass++
#define ir_bass_d 0x807F4AB5 // IR bass--
#define ir_mid_i 0x807F6897 // IR mid++
#define ir_mid_d 0x807FE817 // IR mid--
#define ir_treb_i 0x807FAA55 // IR treb++
#define ir_treb_d 0x807F6A95 // IR treb--
*//*
#define ir_fl_i 0xFF807F // IR fl++
#define ir_fl_d 0xFF20DF // IR fl--
#define ir_fr_i 0xFF40BF // IR fr++
#define ir_fr_d 0xFFA05F // IR fr--
#define ir_cn_i 0xFFC03F // IR cn++
#define ir_cn_d 0xFF609F // IR cn--
#define ir_sl_i 0xFFE01F // IR sl++
#define ir_sl_d 0xFF50AF // IR sl--
#define ir_sr_i 0xFF10EF // IR sr++
#define ir_sr_d 0xFF00FF // IR sr--
#define ir_sub_i 0xFF906F // IR sub++
#define ir_sub_d 0xFF6897 // IR sub--
#define ir_smode 0xFF38C7 // IR speaker mode change
#define ir_equ 0xFF8877 // IR equalizer change
#define ir_tombol 0xFFB24D // IR Menu
#define ir_up 0xFFE21D // IR Up
#define ir_down 0xFFD22D // IR Down
#define ir_left 0xFF12ED // IR Left
#define ir_right 0xFF52AD // IR Right
*/
//IR DEC ----------------------------------
/*#define ir_power 64 // IR power ON/OFF
#define ir_mute 18 // IR mute
#define ir_in 29 // IR input select
#define ir_vol_i 12 // IR vol++
#define ir_vol_d 24 // IR vol--
*/
//remote software Wokwi
#define ir_power 0xFF45BA // IR power ON/OFF
#define ir_mute 0xFF44BB // IR mute
#define ir_in 0XFF47B8 // IR input select
#define ir_vol_i 0xFF40BF // IR vol++
#define ir_vol_d 0xFF19E6 // IR vol--
#define ir_bass 0xFF0CF3 // IR bass
#define ir_mid 0xFF18E7 // IR mid
#define ir_treb 0xFF5EA1 // IR treb
#define ir_fl 0xFF08F7 // IR fl
#define ir_fr 0xFF1CE3 // IR fr
#define ir_cn 0xFF5AA5 // IR cn
#define ir_sl 0xFF42BD // IR sl
#define ir_sr 0xFF52AD // IR sr
#define ir_sub 0xFF4AB5 // IR sub
#define ir_smode 28 // IR speaker mode change
#define ir_equ 17 // IR equalizer change
#define ir_tombol 77 // IR Menu
#define ir_up 74 // IR Up
#define ir_down 75 // IR Down
#define ir_left 0xFF07F8 // IR Left
#define ir_right 0xFF09F6 // IR Right
byte custom_num[8][8] = {
{ B00111, B01111, B11111, B11111, B11111, B11111, B11111, B11111 },
{ B11111, B11111, B11111, B00000, B00000, B00000, B00000, B00000 },
{ B11100, B11110, B11111, B11111, B11111, B11111, B11111, B11111 },
{ B11111, B11111, B11111, B11111, B11111, B11111, B01111, B00111 },
{ B00000, B00000, B00000, B00000, B00000, B11111, B11111, B11111 },
{ B11111, B11111, B11111, B11111, B11111, B11111, B11110, B11100 },
{ B11111, B11111, B11111, B00000, B00000, B00000, B11111, B11111 },
{ B11111, B11111, B11111, B11111, B11111, B11111, B11111, B11111 }
};
const int digit_width = 3;
// 0 1 2 3 4 5 6 7 8 9
const char custom_num_top[10][digit_width]={0,1,7,1,2,32,6,6,5,6,6,7, 0, 4,7,0,6,6,0,6,6, 1, 1,7,0,6,7,0,6,7 };
const char custom_num_bot[10][digit_width]={7,4,5,4,7, 4,7,4,4,4,4,5,32,32,5,4,4,5,7,4,5,32,32,7,7,4,5,4,4,5 };
LiquidCrystal lcd(10, 9, 5, 6, 7, 8); // RS,E,D4,D5,D6,D7
unsigned long time;
int in,power,a,b,volume,vol_1,vol_10,bass,mid,treb,fl,fr,cn,rl,rr,sub,ch_mute,mute_sel,effect_sel,tone_sel;
int equ,ton,trimvol,func,trimmute,mute,fsurr,fmix,smode,mall;
int menu,subMenu,subMenuValue,tampil,return_d,ir_on,ir_menu,vol_on;
int ir_command;
//=====================================
//#include <ClickEncoder.h>
//#include <TimerOne.h>
//ClickEncoder *encoder;
int16_t last, value;
boolean up = false;
boolean down = false;
boolean tombol = false;
boolean reset = false;
//=====================================
//display analizer---------------------
#include <fix_fft.h>
#define DEBUG 0
#define L_IN A3 // Audio input A0 Arduino
#define R_IN A2 // Audio input A1 Arduino
const int Yres = 8;
const int gain = 3;
float peaks[64];
char im[64], data[64];
char Rim[64], Rdata[64];
char data_avgs[64];
int debugLoop;
int i;
int load;
// Custom CHARACTERS
byte v1[8] = { B00000, B00000, B00000, B00000, B00000, B00000, B00000, B11111 };
byte v2[8] = { B00000, B00000, B00000, B00000, B00000, B00000, B11111, B11111 };
byte v3[8] = { B00000, B00000, B00000, B00000, B00000, B11111, B11111, B11111 };
byte v4[8] = { B00000, B00000, B00000, B00000, B11111, B11111, B11111, B11111 };
byte v5[8] = { B00000, B00000, B00000, B11111, B11111, B11111, B11111, B11111 };
byte v6[8] = { B00000, B00000, B11111, B11111, B11111, B11111, B11111, B11111 };
byte v7[8] = { B00000, B11111, B11111, B11111, B11111, B11111, B11111, B11111 };
byte v8[8] = { B11111, B11111, B11111, B11111, B11111, B11111, B11111, B11111 };
//-------------------------------------
void setup() {
Wire.begin();
Serial.begin(9600);
//IrReceiver.begin(IR_RECEIVE_PIN);
irrecv.enableIRIn();
pinMode(LcdBacklight, OUTPUT); // Anoda LCD
digitalWrite(LcdBacklight, HIGH);
lcd.begin(16, 2);
power = 0;
eeprom_read();
power_up();
/*
//=====================================
encoder = new ClickEncoder(11, 12, 13);
encoder->setAccelerationEnabled(false);
Timer1.initialize(1000);
Timer1.attachInterrupt(timerIsr);
last = encoder->getValue();
//=====================================
*/
pinMode(11, INPUT);
pinMode(12, INPUT);
pinMode(13, INPUT_PULLUP);
lcd.createChar(1, v1);
lcd.createChar(2, v2);
lcd.createChar(3, v3);
lcd.createChar(4, v4);
lcd.createChar(5, v5);
lcd.createChar(6, v6);
lcd.createChar(7, v7);
lcd.createChar(8, v8);
for (i=0;i<100;i++)
{
for (load = 0; load < i / 5; load++)
{
lcd.setCursor(load, 1);
lcd.write(5);
}
if (load < 1)
{
lcd.setCursor(0, 1);
lcd.write(5);
}
lcd.setCursor(load + 1, 1);
lcd.write((i - i / 5 * 5) + 1);
for (load = load + 2; load < 20; load++)
{
lcd.setCursor(load, 1);
lcd.write(9);
}
lcd.setCursor(0, 0);
lcd.print(F("LOADING............."));
delay(10);
}
lcd.clear();
delay(10);
//-------------------------------------
}
//void timerIsr() {
// encoder->service();
//}
int powerflag=0;
void loop(){
if (power==0 && millis()-time>60000){ digitalWrite(LcdBacklight, LOW); }
if (menu==0 || menu==4 || menu==5){ custom_num_shape(); }
//----------------------------
//if (millis()-time>30000) grafik();
//else
//----------------------------
updateLCD();
eeprom_update();
ir_control();
return_delay();
/*
//mute -------------------------------------------------//
if (analogRead(sw05) > 900) {
mute++;
set_mute();
delay(btn_delay);
if (menu != 0) {
lcd.clear();
menu = 0;
}
if(mute == 1) {
vol_on = 1;
} else {
vol_on = 0;
}
}
}*/
readRotaryEncoder();
readbutton();
if (tombol){
tombol=false;
if (power==0){ power=1; power_up(); delay(300); }
if (power==1){
if (menu==4){
if (tampil==0){ if (ton >=0 && ton <3){ tampil=1; }}
else { menu=3; tampil=0; }
}
if (menu==5){
if (tampil==0){ if (trimvol >=0 && trimvol <6){ tampil=1; }}
else { menu=4; tampil=0; }
}
if (menu==6){
if (tampil==0){ if (func >=0 && func <2){ tampil=1; }}
else { menu=5; tampil=0; }
}
if (tampil==0){ menu ++;
if (menu == 4 || menu == 5 || menu == 6) lcd.clear();
if (menu > 6){menu=0; }
}
}
btn_cl();
}
if (reset){ reset=false; set_reset(); }
if (power==1){
updateValue();
if (tampil==1) btn_cl();
}
}
//power up --------------------------------------------------------------------------------//
void power_up() {
if(power == 1) {
digitalWrite(LcdBacklight, HIGH);
// digitalWrite(sw07, HIGH);
mute = 1;
lcd.clear();
delay(500);
lcd.setCursor(0, 0);
lcd.print(F(" A2T TECHNO "));
delay(500);
lcd.setCursor(0, 1);
lcd.print(F("5.1 Audio System"));
delay(2000);
lcd.clear();
mute = 0;
pt2322_input_sw();
pt2322_function(0, 1, 0);
set_vol();
set_bass();
set_mid();
set_treb();
set_in();
set_fsurr();
set_fmix();
set_fl();
set_fr();
set_cn();
set_rl();
set_rr();
set_sub();
set_mute();
set_smode();
set_equ();
delay(300);
menu = -1;
//=============
subMenu = 0;
subMenuValue = 0;
tampil=0;
//=============
ir_on = 1;
ir_menu = 0;
vol_on = 0;
} else {
// digitalWrite(sw07, LOW);
mute = 1;
set_mute();
delay(100);
menu = 100;
ir_on = 0;
time=millis();
}
}
void set_reset(){
reset=false;
power = 0;
mute = 1; // mute On
set_mute();
in = 4; // input DVD
volume = 0;
equ = 0; // equalizer Normal
fl = 0; // front left
fr = 0; // front right
cn = 0; // center
rl = 0; // rear left
rr = 0; // rear right
sub = 0; // subwoofer
fsurr = 0; // surround On
fmix = 0; // mixed 0dB
smode = 3; // speaker mode 5.1
lcd.clear();
digitalWrite(LcdBacklight, LOW);
delay(2000);
digitalWrite(LcdBacklight, HIGH);
lcd.setCursor(0, 0);
lcd.print(F(" RESET ALL "));
delay(500);
lcd.setCursor(0, 1);
lcd.print(F("Please wait ...."));
delay(5000);
lcd.clear();
mute = 0;
pt2322_input_sw();
pt2322_function(0, 1, 0);
set_in();
set_vol();
set_equ();
set_fl();
set_fr();
set_cn();
set_rl();
set_rr();
set_sub();
set_mute();
set_smode();
set_fsurr();
set_fmix();
delay(300);
menu = -1;
subMenu = 0;
subMenuValue = 0;
tampil=0;
power = 1;
for (int i=0; i < 25; i++){
volume++;
set_vol();
menu = 0;
updateLCD();
delay(150);
}
}
void updateLCD(){
lcd.setCursor(0,0);
switch (menu){
//volume --------------------------------------------//
case 0:
//input ------------
input(in);
//equalizer---------
equa(equ);
//speaker mode------
spmode(smode);
//volume-----------
lcd.setCursor(0,1);
switch (mute){
case 0: lcd.print(F("VOL>")); bigFont(volume,5); break;
case 1: lcd.print(F("MUT<")); bigFont(0,5); break;
}
lcd.setCursor(3,0); lcd.print(F(" "));
lcd.setCursor(12,0); lcd.print(F(" "));
lcd.setCursor(12,1); lcd.print(F(" "));
break;
case 1:
//input --------------------------------------------//
subMenu = in;
input(subMenu);
lcd.setCursor(3,0); lcd.print(F("<"));
lcd.setCursor(3,1); lcd.print(F(" "));
lcd.setCursor(12,0); lcd.print(F(" "));
lcd.setCursor(12,1); lcd.print(F(" "));
//==================
break;
case 2:
//sound mode --------------------------------------//
subMenu = equ;
equa(subMenu);
lcd.setCursor(3,0); lcd.print(F(" "));
lcd.setCursor(3,1); lcd.print(F(" "));
lcd.setCursor(12,0); lcd.print(F(">"));
lcd.setCursor(12,1); lcd.print(F(" "));
break;
case 3:
//speaker mode -----------------------------------//
subMenu = smode;
spmode(subMenu);
lcd.setCursor(3,0); lcd.print(F(" "));
lcd.setCursor(3,1); lcd.print(F(" "));
lcd.setCursor(12,0); lcd.print(F(" "));
lcd.setCursor(12,1); lcd.print(F(">"));
break;
//tone control -------------------------//
case 4:
subMenu = ton;
lcd.print(F("TONE CTL"));
lcd.setCursor(0,1);
switch (subMenu){
case 0: lcd.print(F("Bass ")); bigFont(bass,9); break;
case 1: lcd.print(F("Middle ")); bigFont(mid,9); break;
case 2: lcd.print(F("Treble ")); bigFont(treb,9); break;
case 3:
lcd.print(F("BACK "));
lcd.setCursor(9,0);
lcd.print(F(" "));
break;
}
break;
case 5:
subMenu = trimvol;
lcd.print(F("TRIM VOL"));
lcd.setCursor(0,1);
switch (subMenu){
case 0: lcd.print(F("Front L ")); bigFont(fl,9); break;
case 1: lcd.print(F("Front R ")); bigFont(fr,9); break;
case 2: lcd.print(F("Center ")); bigFont(cn,9); break;
case 3: lcd.print(F("Rear L ")); bigFont(rl,9); break;
case 4: lcd.print(F("Rear R ")); bigFont(rr,9); break;
case 5: lcd.print(F("Subwoofer")); bigFont(sub,9); break;
case 6:
lcd.print(F("Back "));
lcd.setCursor(9,0);
lcd.print(F(" "));
break;
}
lcd.setCursor(12,0); lcd.print(F(" "));
lcd.setCursor(12,1); lcd.print(F(" "));
break;
case 6:
subMenu = func;
lcd.print(F("FUNCTION "));
lcd.setCursor(0,1);
switch (subMenu){
case 0:
lcd.print(F("Surround "));
lcd.setCursor(9,1);
subMenuValue=fsurr;
switch (subMenuValue){
case 0: lcd.print(F("ACTIVE ")); break;
case 1: lcd.print(F("OFF ")); break;
}
break;
case 1:
lcd.print(F("Mixed "));
lcd.setCursor(6,1);
subMenuValue=fmix;
switch (subMenuValue){
case 0: lcd.print(F(" 0dB ")); break;
case 1: lcd.print(F("+6dB ")); break;
}
break;
case 2:
lcd.print(F("Back "));
break;
}
break;
case 100:
lcd.setCursor(0, 0);
lcd.print(F(" "));
lcd.setCursor(0, 1);
if (digitalRead(LcdBacklight)==LOW){
lcd.print(F(" "));
} else { lcd.print(F(" Stand by ")); }
break;
}
}
void input(int smenu){
lcd.setCursor(0,0);
switch (smenu){
case 0: lcd.print(F("AUX")); break;
case 1: lcd.print(F("FM ")); break;
case 2: lcd.print(F("USB")); break;
case 3: lcd.print(F("TV ")); break;
case 4: lcd.print(F("DVD")); break;
}
}
void equa(int smenu){
lcd.setCursor(13,0);
switch (smenu){
case 0: lcd.print(F("NOR")); break;
case 1: lcd.print(F("POP")); break;
case 2: lcd.print(F("ROC")); break;
case 3: lcd.print(F("CLA")); break;
}
}
void spmode(int smenu){
lcd.setCursor(13,1);
switch (smenu){
case 0: lcd.print(F("2.1")); break;
case 1: lcd.print(F("3.1")); break;
case 2: lcd.print(F("4.1")); break;
case 3: lcd.print(F("5.1")); break;
}
}
void bigFont(int aValue, int lokasi){
int x = aValue;
b = x % 10;
a = (x - b) / 10;
lcd.setCursor(lokasi, 0); for(int i=0; i < digit_width; i++) lcd.write(custom_num_top[a][i]);
lcd.setCursor(lokasi, 1); for(int i=0; i < digit_width; i++) lcd.write(custom_num_bot[a][i]);
lcd.setCursor(lokasi+4, 0); for(int i=0; i < digit_width; i++) lcd.write(custom_num_top[b][i]);
lcd.setCursor(lokasi+4, 1); for(int i=0; i < digit_width; i++) lcd.write(custom_num_bot[b][i]);
}
// Down - Up Rotary encoder
void readRotaryEncoder(){ /*
value += encoder->getValue();
if (value/2 > last) {
last = value/2;
down = true;
delay(150);
} else if (value/2 < last) {
last = value/2;
up = true;
delay(150);
}*/
if (digitalRead(11)==LOW) up=true;
if (digitalRead(12)==LOW) down=true;
delay(150);
}
void readbutton(){ /*
ClickEncoder::Button b = encoder->getButton();
if (b != ClickEncoder::Open) {
switch (b) {
case ClickEncoder::Clicked:
tombol=true;
break;
case ClickEncoder::Held:
reset=true;
break;
}
} */
if (digitalRead(13)==LOW) tombol=true;
}
void updateValue(){
int aValue=0;
if (up){ up=false; aValue=1; }
if (down){ down=false; aValue=-1; }
switch (menu){
case 0: volume+=aValue; set_vol(); break;
case 1: in+=aValue; set_in(); break;
case 2: equ+=aValue; set_equ(); break;
case 3: smode+=aValue; set_smode(); break;
case 4:
if (tampil==0){ ton+=aValue; if (ton > 3) ton = 0; if (ton < 0) ton = 3; }
if (tampil==1){
switch (ton){
case 0: bass+=aValue; set_bass(); break;
case 1: mid+=aValue; set_mid(); break;
case 2: treb+=aValue; set_treb(); break;
case 3: tampil=0; break;
}
}
break;
case 5:
if (tampil==0){ trimvol+=aValue; if (trimvol > 6) trimvol = 0; if (trimvol < 0) trimvol = 6; }
if (tampil==1){
switch (trimvol){
case 0: fl+=aValue; set_fl(); break;
case 1: fr+=aValue; set_fr(); break;
case 2: cn+=aValue; set_cn(); break;
case 3: rl+=aValue; set_rl(); break;
case 4: rr+=aValue; set_rr(); break;
case 5: sub+=aValue; set_sub(); break;
case 6: tampil=0; break;
}
}
break;
case 6:
if (tampil==0){ func+=aValue; if (func > 2) func = 0; if (func < 0) func = 2; }
if (tampil==1){
switch (func){
case 0: fsurr+=aValue; set_fsurr(); break;
case 1: fmix+=aValue; set_fmix(); break;
case 2: tampil=0; break;
}
}
break;
}
ir_cl;
}
//eeprom --------------------------------------------------------------------------------//
void eeprom_update(){
EEPROM.update(0, in);
EEPROM.update(1, volume);
EEPROM.update(2, bass);
EEPROM.update(3, mid);
EEPROM.update(4, treb);
EEPROM.update(5, fl);
EEPROM.update(6, fr);
EEPROM.update(7, cn);
EEPROM.update(8, rl);
EEPROM.update(9, rr);
EEPROM.update(10, sub);
EEPROM.update(11, equ);
EEPROM.update(12, fsurr);
EEPROM.update(13, fmix);
EEPROM.update(14, smode);
}
void eeprom_read(){
in = EEPROM.read(0);
volume = EEPROM.read(1);
bass = EEPROM.read(2);
mid = EEPROM.read(3);
treb = EEPROM.read(4);
fl = EEPROM.read(5);
fr = EEPROM.read(6);
cn = EEPROM.read(7);
rl = EEPROM.read(8);
rr = EEPROM.read(9);
sub = EEPROM.read(10);
equ = EEPROM.read(11);
fsurr = EEPROM.read(12);
fmix = EEPROM.read(13);
smode = EEPROM.read(14);
}
void btn_cl() {
delay(btn_delay);
time = millis();
return_d = 1;
}
void ir_cl() {
time = millis();
return_d = 1;
}
void return_delay() {
if (millis() - time > 10000 && return_d == 1 && menu != 0 && mute == 0) {
menu = 0;
tampil = 0;
subMenu = 0;
return_d = 0;
ir_menu = 0;
lcd.clear();
}
}
unsigned long key_value = 0;
void ir_control() {
if ( irrecv.decode(&results)){
// if ( irrecv.decode()){
if (results.value == 0xFFFFFFFF) {
results.value = key_value;
}
switch(results.value) {
// switch(irrecv.decodedIRData.command) {
//power -------------------------------------------------//
case ir_power:
if (powerflag==0){ powerflag=1; }
else { powerflag=0; }
switch (powerflag){
case 0: power=0; power_up(); delay(300); break;
case 1: power=1; power_up(); delay(300); break;
}
}
if (ir_on == 1) {
switch(results.value) {
// switch(irrecv.decodedIRData.command) {
//mute -------------------------------------------------//
case ir_mute:
if (menu>3){ lcd.clear(); }
mute++;
set_mute();
menu=0; tampil=0; ir_menu = 0;
if(mute == 1) {
vol_on = 1;
} else {
vol_on = 0;
}
break;
//select input -------------------------------------------------//
case ir_in:
if (menu>3){menu=0; lcd.clear(); updateLCD();}
if (menu==1){ up=true; } menu=1; tampil=0; ir_menu = 1;
break;
}
}
if (ir_on == 1 && vol_on == 0) {
if (ir_on == 1) {
switch(results.value) {
// switch(irrecv.decodedIRData.command) {
//volume -------------------------------------------------//
case ir_vol_i:
if (menu>3) lcd.clear();
if (menu==0){ up=true; } menu=0; tampil=0; ir_menu = 0;
break;
case ir_vol_d:
if (menu>3) lcd.clear();
if (menu==0){ down=true; } menu=0; tampil=0; ir_menu = 0;
break;
//sound mode -------------------------------------------------//
case ir_equ:
if (menu>3){menu=0; lcd.clear(); updateLCD();}
if (menu==2){ up=true; } menu=2; tampil=0; ir_menu = 2;
break;
//speaker mode -------------------------------------------------//
case ir_smode:
if (menu>3){menu=0; lcd.clear(); updateLCD();}
if (menu==3){ up=true; } menu=3; tampil=0; ir_menu = 3;
break;
case ir_up:
//up=true;
break;
case ir_down:
//down=true;
break;
case ir_left:
down=true;
break;
case ir_right:
up=true;
break;
//bass -------------------------------------------------//
case ir_bass:
menu=4; tampil=1; ton=0; ir_cl(); ir_menu = 4;
//sound_mode = 0;
break;
case ir_mid:
menu=4; tampil=1; ton=1; ir_cl(); ir_menu = 4;
//sound_mode = 0;
break;
//treb -------------------------------------------------//
case ir_treb:
menu=4; tampil=1; ton=2; ir_cl(); ir_menu = 4;
//sound_mode = 0;
break;
case ir_fl:
if (menu<4){ lcd.clear(); updateLCD(); }
menu=5; tampil=1; trimvol=0; ir_menu = 5;
break;
//FR -------------------------------------------------//
case ir_fr:
if (menu<4){ lcd.clear(); updateLCD(); }
menu=5; tampil=1; trimvol=1; ir_menu = 5;
break;
//CN -------------------------------------------------//
case ir_cn:
if (menu<4){ lcd.clear(); updateLCD(); }
menu=5; tampil=1; trimvol=2; ir_menu = 5;
break;
//SL -------------------------------------------------//
case ir_sl:
if (menu<4){ lcd.clear(); updateLCD(); }
menu=5; tampil=1; trimvol=3; ir_menu = 5;
break;
//SR -------------------------------------------------//
case ir_sr:
if (menu<4){ lcd.clear(); updateLCD(); }
menu=5; tampil=1; trimvol=4; ir_menu = 5;
break;
//sub -------------------------------------------------//
case ir_sub:
if (menu<4){ lcd.clear(); updateLCD(); }
menu=5; tampil=1; trimvol=5; ir_menu = 5;
break;
}
if (ir_menu == 0 && menu != 0) {
lcd.clear();
menu = 0;
}
if (ir_menu == 1 && menu != 1) {
lcd.clear();
menu = 1;
}
if (ir_menu == 2 && menu != 2) {
lcd.clear();
menu = 2;
}
if (ir_menu == 3 && menu != 3) {
lcd.clear();
menu = 3;
}
if (ir_menu == 4 && menu != 4) {
lcd.clear();
menu = 4;
}
if (ir_menu == 5 && menu != 5) {
lcd.clear();
menu = 5;
}
if (ir_menu == 6 && menu != 6) {
lcd.clear();
menu = 6;
}
}
}
key_value = results.value;
irrecv.resume();
delay(300);
ir_cl();
}
}
//custom shape --------------------------------------------------------------------------------//
void custom_num_shape(){
for(int i=0; i < 8; i++)
lcd.createChar(i, custom_num[i]);
}
void set_smode(){
if (smode > 3) smode = 0;
if (smode < 0) smode = 3;
switch(smode){
case 0: // 2.1 (fl,fr,sub = on, cn,rl,rs = off)
ch_mute=1; fsurr=1;
set_cn();
set_rl();
set_rr();
set_fsurr();
break;;
case 1: // 3.1 (fl,fr,cn,sub = on, rl,rs = off)
ch_mute=0; fsurr=0;
set_cn();
ch_mute=1;
set_rl();
set_rr();
set_fsurr();
break;
case 2: // 4.1 (fl,fr,rl,rs,sub = on, cn = off)
ch_mute=1; fsurr=0;
set_cn();
ch_mute=0;
set_rl();
set_rr();
set_fsurr();
break;
case 3: // 5.1 (fl,fr,cn,rl,rs,sub = on)
ch_mute=0; fsurr=0;
set_cn();
set_rl();
set_rr();
set_fsurr();
break;
}
}
void set_equ(){
if (equ > 3) equ = 0;
if (equ < 0) equ = 3;
switch(equ) {
case 0: // Normal
bass = 7;
mid = 7;
treb = 7;
break;
case 1: // Pop
bass = 4;
mid = 10;
treb = 5;
break;
case 2: // Rock
bass = 11;
mid = 5;
treb = 12;
break;
case 3: // Classic
bass = 7;
mid = 7;
treb = 5;
break;
}
set_bass();
set_mid();
set_treb();
}
//pt2323 settings --------------------------------------------------------------------------------//
void set_in(){
if (in > 4) in = 0;
if (in < 0) in = 4;
switch(in){
case 0: a = 0b11001011; break; // 1 input
case 1: a = 0b11001010; break; // 2 input
case 2: a = 0b11001001; break; // 3 input
case 3: a = 0b11001000; break; // 4 input
case 4: a = 0b11000111; break; // 6 CH input
}
pt2323_send(a);
}
void set_fmute(){
if (mute > 1) { mute = 0; }
switch(mute){
case 0: a = 0b11111110; break; // All CH mute disabled
case 1: a = 0b11111111; break; // All CH mute
}
pt2323_send(a);
}
void set_fsurr(){
if (fsurr > 1) fsurr=0;
if (fsurr < 0) fsurr=1;
switch(fsurr){
case 0: a = 0b11010000; break; // Surround ON
case 1: a = 0b11010001; break; // Surround OFF
}
pt2323_send(a);
}
void set_fmix(){
if (fmix > 1) fmix=0;
if (fmix < 0) fmix=1;
switch(fmix){
case 0: a = 0b10010000; break; // 0dB setup
case 1: a = 0b10010001; break; // +6dB setup
}
pt2323_send(a);
}
void set_mute(){
if (mute > 1){ mute = 0; }
switch(mute){
case 0: a = 0b11111110; break; // All CH mute disabled
case 1: a = 0b11111111; break; // All CH mute
}
pt2323_send(a);
}
//pt2322 settings --------------------------------------------------------------------------------//
void pt2322_function(int pt2322_mute, int effect, int tone_ctrl) {
switch(pt2322_mute){
case 0: mute_sel = 0b00000000; break;
case 1: mute_sel = 0b00001000; break;
}
switch(effect){
case 0: effect_sel = 0b00000000; break;
case 1: effect_sel = 0b00000100; break;
}
switch(tone_ctrl){
case 0: tone_sel = 0b00000000; break;
case 1: tone_sel = 0b00000010; break;
}
pt2322_send(0b01110000 + mute_sel + effect_sel + tone_sel);
}
void set_vol(){
if (volume > 79) volume = 79;
if (volume < 0) volume = 0;
if (volume == 0) mute = 1;
//else mute = 0;
set_mute();
int c = 79 - volume;
vol_1 = c % 10;
vol_10 = (c - vol_1) / 10;
a = vol_10 + 0b11100000;
b = vol_1 + 0b11010000;
Wire.beginTransmission(PT2322_address);
Wire.write (a);
Wire.write (b);
Wire.endTransmission();
}
void set_bass(){
if (bass > 15) bass = 15;
if (bass < 0) bass = 0;
a = bass;
if(bass > 7){ a = 23 - bass; }
pt2322_send(0b10010000 + a);
}
void set_mid(){
if (mid > 15) mid = 15;
if (mid < 0) mid = 0;
a = mid;
if(mid > 7){ a = 23 - mid; }
pt2322_send(0b10100000 + a);
}
void set_treb(){
if (treb > 15) treb = 15;
if (treb < 0) treb = 0;
a = treb;
if(treb > 7){ a = 23 - treb; }
pt2322_send(0b10110000 + a);
}
void set_fl(){
if (fl > 15) fl = 15;
if (fl < 0) fl = 0;
int c = 15 - fl;
pt2322_send(0b00010000 + c);
}
void set_fr(){
if (fr > 15) fr = 15;
if (fr < 0) fr = 0;
int c = 15 - fr;
pt2322_send(0b00100000 + c);
}
void set_cn(){
if (cn > 15) cn = 15;
if (cn < 0) cn = 0;
int c = 15 - cn;
switch(ch_mute){
case 0: a = 0b11110100; break; // CN mute disabled
case 1: a = 0b11110101; break; // CN mute
}
pt2323_send(a);
pt2322_send(0b00110000 + c);
}
void set_rl(){
if (rl > 15) rl = 15;
if (rl < 0) rl = 0;
int c = 15 - rl;
switch(ch_mute){
case 0: a = 0b11111000; break; // RL mute disabled
case 1: a = 0b11111001; break; // RL mute
}
pt2323_send(a);
pt2322_send(0b01000000 + c);
}
void set_rr(){
if (rr > 15) rr = 15;
if (rr < 0) rr = 0;
int c = 15 - rr;
switch(ch_mute){
case 0: a = 0b11111010; break; // RR mute disabled
case 1: a = 0b11111011; break; // RR mute
}
pt2323_send(a);
pt2322_send(0b01010000 + c);
}
void set_sub(){
if (sub > 15) sub = 15;
if (sub < 0) sub = 0;
int c = 15 - sub;
pt2322_send(0b01100000 + c);
}
//pt2323 & pt2322 send --------------------------------------------------------------------------------//
void pt2323_send(char c){
Wire.beginTransmission(PT2323_address);
Wire.write (c);
Wire.endTransmission();
}
void pt2322_input_sw() {
Wire.beginTransmission(PT2322_address);
Wire.write (0b11000111);
Wire.endTransmission();
}
void pt2322_send(char c){
Wire.beginTransmission(PT2322_address);
Wire.write (c);
Wire.endTransmission();
}
//end code
/* ini untuk tampilan grafik analizer
/* FFT_TEST4
Ray Burnette 20130810 function clean-up & 1284 port (328 verified)
Uses 2x16 Parallel LCD in 4-bit mode, see LiquidCrystal lib call for details
http://forum.arduino.cc/index.php?PHPSESSID=4karr49jlndufvtlqs9pdd4g96&topic=38153.15
Modified by varind in 2013: this code is public domain, enjoy!
http://www.variableindustries.com/audio-spectrum-analyzer/
328P = Binary sketch size: 5,708 bytes (of a 32,256 byte maximum)
1284P= Binary sketch size: 5,792 bytes (of a 130,048 byte maximum) Free RAM = 15456
Binary sketch size: 8,088 bytes (of a 130,048 byte maximum) (Debug)
*/
/*
#include <Wire.h>
#include <LiquidCrystal.h>
*/
void grafik() {
for (int i = 0; i < 64; i++) { // 64 bins = 32 bins of usable spectrum data
data[i] = ((analogRead(L_IN) / 8 ) - 256); // chose how to interpret the data from analog in
im[i] = 0; // imaginary component
Rdata[i] = ((analogRead(R_IN) / 8 ) - 256); // chose how to interpret the data from analog in
Rim[i] = 0; // imaginary component
}
fix_fft(data, im, 6, 0); // Send Left channel normalized analog values through fft
fix_fft(Rdata, Rim, 6, 0); // Send Right channel normalized analog values through fft
// At this stage, we have two arrays of [0-31] frequency bins deep [32-63] duplicate
// calculate the absolute values of bins in the array - only want positive values
for (int i = 0; i < 40; i++) {
data[i] = sqrt(data[i] * data[i] + im[i] * im[i]);
Rdata[i] = sqrt(Rdata[i] * Rdata[i] + Rim[i] * Rim[i]);
// COPY the Right low-band (0-15) into the Left high-band (16-31) for display ease
if (i < 20) {
data_avgs[i] = data[i];
}
else {
data_avgs[i] = Rdata[i - 20];
}
// Remap values to physical display constraints... that is, 8 display custom character indexes + "_"
data_avgs[i] = constrain(data_avgs[i], 0, 9 - gain); //data samples * range (0-9) = 9
data_avgs[i] = map(data_avgs[i], 0, 9 - gain, 0, Yres); // remap averaged values
}
Two16_LCD();
decay(1);
}
void Two16_LCD() {
lcd.setCursor(0, 0);
lcd.print(F("L")); // Channel ID replaces bin #0 due to hum & noise
lcd.setCursor(0, 1);
lcd.print(F("R")); // ditto
for (int x = 1; x < 20; x++) { // init 0 to show lowest band overloaded with hum
int y = x + 20; // second display line
if (data_avgs[x] > peaks[x]) peaks[x] = data_avgs[x];
if (data_avgs[y] > peaks[y]) peaks[y] = data_avgs[y];
lcd.setCursor(x, 0); // draw first (top) row Left
if (peaks[x] == 0) {
lcd.print(F("_")); // less LCD artifacts than " "
}
else {
lcd.write(peaks[x]);
}
lcd.setCursor(x, 1); // draw second (bottom) row Right
if (peaks[y] == 0) {
lcd.print(F("_"));
}
else {
lcd.write(peaks[y]);
}
}
debugLoop++;
if (DEBUG && (debugLoop > 99)) {
Serial.print( "Free RAM = " );
Serial.println( freeRam(), DEC);
Serial.println( millis(), DEC);
debugLoop = 0;
}
}
int freeRam () {
extern int __heap_start, *__brkval;
int v;
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}
void decay(int decayrate) {
int DecayTest = 1;
// reduce the values of the last peaks by 1
if (DecayTest == decayrate) {
for (int x = 0; x < 40; x++) {
peaks[x] = peaks[x] - 1; // subtract 1 from each column peaks
DecayTest = 0;
}
}
DecayTest++;
}