Skip to main content

AX2358 Homemade 5.1 Remote Kit with 16x2 LCD

AX2358 Homemade 5.1 Remote Kit with 16x2 LCD


                                             

AX2358 is I used for this 5.1 remote kit project. It is Built-in 2-channel to 6-channel converter and 6-channel volume controller. It has 4 stereo inputs and one 6 channel input. Any stereo input terminals of AX2358 are selected, it will be directly converted to 6 channels and then output through volume adjustment but when the signal from the 6-channel input terminal is selected, it directly enters the volume adjustment and then outputs it without any processing. It has 6-channel individual volume control in this IC (0 to -79dB, 1dB/step).

This IC working by I2C communication. The data are transmitted to the AX2358 via the SDA and SCL. So I need a microcontroller. I choose the microcontroller is Atmega328 for this. This microcontroller programmed with Arduino UNO.

                                        

Features

  • Power ON/OFF switch
  • Mute switch
  • Input select switch
  • Standby power out ON/OFF
  • 4 Stereo inputs and One 6-channel input
  • Master volume: 0 to 50
  • 6-channels volume: -10 to 10
  • Surround ON/OFF
  • Speaker mode: 5.1/2.1
  • -6dB ON/OFF
  • All reset
  • Remote control

Controller

Used push buttons for Power ON/OFF, Mute/Unmute and Input selection. Rotary encoder for volume up/down and channel/menu select. Long press the rotary encoder's switch for the menu function.

             







Application Circuit

Youtube Video:




Arduino Code

// AX2358 5.1 Surround System

#include <Wire.h>
#include <EEPROM.h>
#include <LiquidCrystal.h>
#include <IRremote.h>

#define AX2358_address 0b1001010

#define btn_delay 300

#define sw01 9          // SW
#define sw02 11         // DT
#define sw03 10         // CLK
#define sw04 A0         // Input
#define sw05 A1         // Mute
#define sw06 A2         // Power

#define sw_power 13     // Out

// IR HEX code
#define ir_power      0x807F827D    // IR power ON/OFF
#define ir_mute       0x807F42BD    // IR mute
#define ir_in_0       0x807F629D    // IR input USB
#define ir_in_1       0x807F52AD    // IR input BLU
#define ir_in_2       0x807FA25D    // IR input FM
#define ir_in_3       0x807F22DD    // IR input AUX
#define ir_in_4       0x807F20DF    // IR input DVD
#define ir_vol_i      0x807F906F    // IR vol++
#define ir_vol_d      0x807FA05F    // IR vol-- 
#define ir_fl_i       0x807F40BF    // IR fl++
#define ir_fl_d       0x807FC03F    // IR fl-- 
#define ir_fr_i       0x807F00FF    // IR fr++
#define ir_fr_d       0x807F807F    // IR fr--
#define ir_sl_i       0x807F48B7    // IR sl++
#define ir_sl_d       0x807FC837    // IR sl--
#define ir_sr_i       0x807F08F7    // IR sr++
#define ir_sr_d       0x807F8877    // IR sr--
#define ir_cn_i       0x807F50AF    // IR cn++
#define ir_cn_d       0x807F609F    // IR cn--
#define ir_sub_i      0x807FD02F    // IR sub++
#define ir_sub_d      0x807FE01F    // IR sub-- 
#define ir_sp_mode    0x807F0AF5    // IR speaker mode change
#define ir_surr_mode  0x807FA857    // IR surround ON/OFF
#define ir_mix_mode   0x00000000    // IR -6dB ON/OFF
#define ir_reset      0x807F1AE5    // IR reset

IRrecv irrecv(8);
decode_results results;

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;
const char custom_num_top[10][digit_width] = { 0, 1, 2, 1, 2, 32, 6, 6, 2, 6, 6, 2, 3, 4, 7,   7, 6, 6, 0, 6, 6, 1, 1, 2,   0, 6, 2, 0, 6, 2};
const char custom_num_bot[10][digit_width] = { 3, 4, 5, 4, 7, 4,  7, 4, 4, 4, 4, 5, 32, 32, 7, 4, 4, 5, 3, 4, 5, 32, 32, 7, 3, 4, 5, 4, 4, 5};

byte arrow_right[8] = {B00000, B10000, B11000, B11100, B11110, B11100, B11000, B10000};

LiquidCrystal lcd(7, 6, 5, 4, 3, 2); // RS,E,D4,D5,D6,D7

unsigned long time;
int in, mute, return_d, surr, mix, a, b, x, power, menu, menu_active, ch_mute, speaker_mode, btn_press, long_press, vol_menu, vol_menu_jup, reset;
int fl, fr, sl, sr, cn, sub, ir_menu, ir_on, mas_vol, fl_vol, fr_vol, sl_vol, sr_vol, cn_vol, sub_vol;

long btn_timer = 0;
long long_press_time = 600;

void setup() {
  Wire.begin();
  Serial.begin(9600);
  irrecv.enableIRIn();

  pinMode(sw01, INPUT);      // SW
  pinMode(sw02, INPUT);      // DT
  pinMode(sw03, INPUT);      // CLK
  pinMode(sw04, INPUT);      // Input
  pinMode(sw05, INPUT);      // Mute
  pinMode(sw06, INPUT);      // Power
  pinMode(sw_power, OUTPUT); // Out

  digitalWrite(sw_power, LOW);

  lcd.begin(16, 2);
  
  power = 0;
  eeprom_read();
  start_up();
  power_up();

}

void loop() {
  lcd_update();
  eeprom_update();
  ir_control();
  return_delay();

  if (menu_active == 0) {
    custom_num_shape();
  } else {
    custom_shape();
  }

  //power -------------------------------------------------//
  if (analogRead(sw06) > 900) {
    power++;
    if (power > 1) {
      power = 0;
    }
    power_up();
    delay(btn_delay);
  }

  if (power == 1) {
    //select input -------------------------------------------------//
    if (analogRead(sw04) > 900) {
      in++;
      set_in();
      delay(btn_delay);
    }

    //select menu -------------------------------------------------//
    if (digitalRead(sw01) == LOW) {
      if (btn_press == 0) {
        btn_press = 1;
        btn_timer = millis();
      }
      if ((millis() - btn_timer > long_press_time) && (long_press == 0) && (menu_active == 0)) {
        long_press = 1;
        menu_active = 1;
        menu = 1;
        btn_cl();
        lcd.clear();
      } else if ((millis() - btn_timer > long_press_time) && (long_press == 0) && (menu_active == 1)) {
        long_press = 1;
        menu_active = 0;
        vol_menu = 0;
        reset = 0;
        btn_cl();
        lcd.clear();
      }
    } else {
      if (btn_press == 1) {
        if (long_press == 1) {
          long_press = 0;
        } else {
          if (menu_active == 1) {
            menu++;
            if (menu > 4) {
              menu = 1;
            }
            btn_cl();
            lcd.clear();
          } else if (menu_active == 0 && speaker_mode == 0) {
            vol_menu++;
            if (vol_menu > 6) {
              vol_menu = 0;
            }
            btn_cl();
          } else if (menu_active == 0 && speaker_mode == 1) {
            vol_menu++;
            if (vol_menu_jup == 0) {
              if (vol_menu > 2) {
                vol_menu = 6;
                vol_menu_jup = 1;
              }
            }
            if (vol_menu_jup == 1) {
              if (vol_menu > 6) {
                vol_menu = 0;
                vol_menu_jup = 0;
              }
            }
            btn_cl();
          }
        }
        btn_press = 0;
      }
    }

    //mute -------------------------------------------------//
    if (analogRead(sw05) > 900 && mas_vol != 19) {
      mute++;
      if (mute == 1) {
        menu_active = 99;
      } else {
        menu_active = 0;
      }
      set_mute();
      delay(btn_delay);
      lcd.clear();
    }
  }

  //menu active 0 -------------------------------------------------//
  if (menu_active == 0) {
    if (digitalRead(sw02) == LOW) {
      if (vol_menu == 0) {
        mas_vol++;
      }
      if (vol_menu == 1) {
        fl_vol++;
      }
      if (vol_menu == 2) {
        fr_vol++;
      }
      if (vol_menu == 3) {
        sl_vol++;
      }
      if (vol_menu == 4) {
        sr_vol++;
      }
      if (vol_menu == 5) {
        cn_vol++;
      }
      if (vol_menu == 6) {
        sub_vol++;
      }
      set_mas_vol();
      set_fl();
      set_fr();
      set_sub();
      if (speaker_mode == 0) {
        set_sl();
        set_sr();
        set_cn();
      }
      btn_cl();
    }
    if (digitalRead(sw03) == LOW) {
      if (vol_menu == 0) {
        mas_vol--;
      }
      if (vol_menu == 1) {
        fl_vol--;
      }
      if (vol_menu == 2) {
        fr_vol--;
      }
      if (vol_menu == 3) {
        sl_vol--;
      }
      if (vol_menu == 4) {
        sr_vol--;
      }
      if (vol_menu == 5) {
        cn_vol--;
      }
      if (vol_menu == 6) {
        sub_vol--;
      }
      set_mas_vol();
      set_fl();
      set_fr();
      set_sub();
      if (speaker_mode == 0) {
        set_sl();
        set_sr();
        set_cn();
      }
      btn_cl();
    }
  }

  //menu active 1 -------------------------------------------------//
  if (menu_active == 1) {
    if (menu == 1) {
      if (digitalRead(sw02) == LOW) {
        surr++;
        set_surr();
        btn_cl();
      }
    }
    if (menu == 2) {
      if (digitalRead(sw02) == LOW) {
        speaker_mode++;
        if (speaker_mode == 1) {
          vol_menu_jup = 0;
        }
        set_speaker_mode();
        btn_cl();
      }
    }
    if (menu == 3) {
      if (digitalRead(sw02) == LOW) {
        mix++;
        set_mix();
        btn_cl();
      }
    }
    if (menu == 4) {
      if (digitalRead(sw02) == LOW) {
        reset++;
        set_reset();
        btn_cl();
      }
    }
  }
}

//eeprom -----------------------------------------------------//

void eeprom_update() {
  EEPROM.update(0, in);
  EEPROM.update(1, mas_vol);
  EEPROM.update(2, fl_vol + 10);
  EEPROM.update(3, fr_vol + 10);
  EEPROM.update(4, sl_vol + 10);
  EEPROM.update(5, sr_vol + 10);
  EEPROM.update(6, cn_vol + 10);
  EEPROM.update(7, sub_vol + 10);
  EEPROM.update(8, surr);
  EEPROM.update(9, speaker_mode);
  EEPROM.update(10, mix);
}

void eeprom_read() {
  in = EEPROM.read(0);
  mas_vol = EEPROM.read(1);
  fl_vol = EEPROM.read(2) - 10;
  fr_vol = EEPROM.read(3) - 10;
  sl_vol = EEPROM.read(4) - 10;
  sr_vol = EEPROM.read(5) - 10;
  cn_vol = EEPROM.read(6) - 10;
  sub_vol = EEPROM.read(7) - 10;
  surr = EEPROM.read(8);
  speaker_mode = EEPROM.read(9);
  mix = EEPROM.read(10);
}

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 > 5000 && return_d == 1 && mute == 0 && menu_active != 0) {
    menu_active = 0;
    vol_menu = 0;
    reset = 0;
    return_d = 0;
    lcd.clear();
  } else if (millis() - time > 5000 && return_d == 1 && mute == 0 && menu_active == 0) {
    vol_menu = 0;
    return_d = 0;
  }
}

//power up -----------------------------------------------------//

void power_up() {
  if (power == 1) {
    lcd.clear();
    delay(500);
    lcd.setCursor(0, 1);
    lcd.print("   LOADING...   ");
    delay(1000);
    lcd.clear();
    if (mas_vol > 19) {
      mute = 0;
    }
    set_mute();
    vol_menu = 0;
    menu_active = 0;
    delay(300);
    ir_on = 1;
    vol_menu_jup = 0;
    digitalWrite(sw_power, HIGH);

  } else {

    digitalWrite(sw_power, LOW);
    mute = 1;
    set_mute();
    delay(100);
    menu_active = 100;
    ir_on = 0;
  }
}

void start_up() {
  mute = 1;
  set_mute();
  delay(500);
  lcd.setCursor(0, 0);
  lcd.print("    Ui Tech     ");
  delay(500);
  lcd.setCursor(0, 1);
  lcd.print("   5.1 SYSTEM   ");
  delay(1000);
  lcd.clear();
  delay(300);
  lcd.setCursor(0, 1);
  lcd.print("   LOADING...   ");
  delay(1500);
  lcd.clear();
  delay(300);
  AX2358();
  set_in();
  set_surr();
  set_mix();
  set_fl();
  set_fr();
  set_sl();
  set_sr();
  set_cn();
  set_sub();
}

//IR control --------------------------------------------------------------------------------//

void ir_control() {
  if ( irrecv.decode( &results )) {

    switch (results.value) {
      //power -------------------------------------------------//
      case ir_power:
        power++;
        if (power > 1) {
          power = 0;
        }
        power_up();
        break;
    }
    if (ir_on == 1) {
      switch (results.value) {
        //mute -------------------------------------------------//
        case ir_mute:
          if (mas_vol != 19) {
            mute++;
            if (mute == 1) {
              menu_active = 99;
            } else {
              menu_active = 0;
            }
            set_mute();
            lcd.clear();  
          }
          
          break;

        //select input -------------------------------------------------//
        case ir_in_0:
          in = 0;
          set_in();
          ir_cl();
          break;

        case ir_in_1:
          in = 1;
          set_in();
          ir_cl();
          break;

        case ir_in_2:
          in = 2;
          set_in();
          ir_cl();
          break;
          
        case ir_in_3:
          in = 3;
          set_in();
          ir_cl();
          break;

        case ir_in_4:
          in = 4;
          set_in();
          ir_cl();
          break;
      }
    }

    if (ir_on == 1 && menu_active == 0) {
      switch (results.value) {
        //VOL -------------------------------------------------//
        case ir_vol_i:
          if (speaker_mode == 0 || speaker_mode == 1) {
            mas_vol++;
            vol_menu = 0;
            set_mas_vol();
            set_fl();
            set_fr();
            set_sub();
            if (speaker_mode == 0) {
              set_sl();
              set_sr();
              set_cn();
            }
          }
          break;

        case ir_vol_d:
          if (speaker_mode == 0 || speaker_mode == 1) {
            mas_vol--;
            vol_menu = 0;
            set_mas_vol();
            set_fl();
            set_fr();
            set_sub();
            if (speaker_mode == 0) {
              set_sl();
              set_sr();
              set_cn();
            }
          }
          break;

        //FL -------------------------------------------------//
        case ir_fl_i:
          if (speaker_mode == 0 || speaker_mode == 1) {
            fl_vol++;
            vol_menu = 1;
            set_fl();
          }
          break;

        case ir_fl_d:
          if (speaker_mode == 0 || speaker_mode == 1) {
            fl_vol--;
            vol_menu = 1;
            set_fl();
          }
          break;

        //FR -------------------------------------------------//
        case ir_fr_i:
          if (speaker_mode == 0 || speaker_mode == 1) {
            fr_vol++;
            vol_menu = 2;
            set_fr();
          }
          break;

        case ir_fr_d:
          if (speaker_mode == 0 || speaker_mode == 1) {
            fr_vol--;
            vol_menu = 2;
            set_fr();
          }
          break;

        //SL -------------------------------------------------//
        case ir_sl_i:
          if (speaker_mode == 0) {
            sl_vol++;
            vol_menu = 3;
            set_sl();
          }
          break;

        case ir_sl_d:
          if (speaker_mode == 0) {
            sl_vol--;
            vol_menu = 3;
            set_sl();
          }
          break;

        //SR -------------------------------------------------//
        case ir_sr_i:
          if (speaker_mode == 0) {
            sr_vol++;
            vol_menu = 4;
            set_sr();
          }
          break;

        case ir_sr_d:
          if (speaker_mode == 0) {
            sr_vol--;
            vol_menu = 4;
            set_sr();
          }
          break;

        //CN -------------------------------------------------//
        case ir_cn_i:
          if (speaker_mode == 0) {
            cn_vol++;
            vol_menu = 5;
            set_cn();
          }
          break;

        case ir_cn_d:
          if (speaker_mode == 0) {
            cn_vol--;
            vol_menu = 5;
            set_cn();
          }
          break;

        //SUB -------------------------------------------------//
        case ir_sub_i:
          if (speaker_mode == 0 || speaker_mode == 1) {
            sub_vol++;
            vol_menu = 6;
            set_sub();
          }
          break;

        case ir_sub_d:
          if (speaker_mode == 0 || speaker_mode == 1) {
            sub_vol--;
            vol_menu = 6;
            set_sub();
          }
          break;

        //speaker mode -------------------------------------------------//
        case ir_sp_mode:
          speaker_mode++;
          vol_menu = 0;
          if (speaker_mode == 1) {
            vol_menu_jup = 0;
          }
          set_speaker_mode();
          break;

        //surround -------------------------------------------------//
        case ir_surr_mode:
          surr++;
          vol_menu = 0;
          set_surr();
          break;

        // -------------------------------------------------//
        case ir_mix_mode:
          mix++;
          vol_menu = 0;
          set_mix();
          break;

        // -------------------------------------------------//
        case ir_reset:
          reset++;
          vol_menu = 0;
          set_reset();
          break;
      }
      ir_cl();
    }
    irrecv.resume();
  }
}

//custom shape --------------------------------------------------------------------------------//

void custom_num_shape() {
  for (int i = 0; i < 8; i++)
    lcd.createChar(i, custom_num[i]);
}

void custom_shape() {
  lcd.createChar(1, arrow_right);
}


//lcd ---------------------------------------------------------//

void lcd_update() {
  int c;
  switch (menu_active) {
    case 0:
      //input -------------------------------------------------//
      lcd.setCursor(0, 0);
      if (in == 0) {
        lcd.print("IN1");
      }
      if (in == 1) {
        lcd.print("IN2");
      }
      if (in == 2) {
        lcd.print("IN3");
      }
      if (in == 3) {
        lcd.print("AUX");
      }
      if (in == 4) {
        lcd.print("DVD");
      }

      //speaker mode ------------------------------------------//
      lcd.setCursor(4, 0);
      if (speaker_mode == 0) {
        lcd.print("5.1");
      }
      if (speaker_mode == 1) {
        lcd.print("2.1");
      }

      //vol ----------------------------------------------//
      switch (vol_menu) {
        case 0:
          lcd.setCursor(0, 1);
          //       ("       ");
          lcd.print("MAS-VOL");
          c = mas_vol - 19;
          break;

        case 1:
          lcd.setCursor(0, 1);
          //       ("       ");
          lcd.print("FL-VOL ");
          c = fl_vol;
          break;

        case 2:
          lcd.setCursor(0, 1);
          //       ("       ");
          lcd.print("FR-VOL ");
          c = fr_vol;
          break;

        case 3:
          lcd.setCursor(0, 1);
          //       ("       ");
          lcd.print("SL-VOL ");
          c = sl_vol;
          break;

        case 4:
          lcd.setCursor(0, 1);
          //       ("       ");
          lcd.print("SR-VOL ");
          c = sr_vol;
          break;

        case 5:
          lcd.setCursor(0, 1);
          //       ("       ");
          lcd.print("CN-VOL ");
          c = cn_vol;
          break;

        case 6:
          lcd.setCursor(0, 1);
          //       ("       ");
          lcd.print("SUB-VOL");
          c = sub_vol;
          break;
      }
      break;

    case 1:
      switch (menu) {
        case 1:
          lcd.setCursor(0, 0);
          lcd.print("Surround");
          lcd.setCursor(1, 1);
          lcd.print("ON");
          lcd.setCursor(6, 1);
          lcd.print("OFF");
          if (surr == 0) {
            lcd.setCursor(0, 1);
            lcd.write(1);
            lcd.setCursor(5, 1);
            lcd.print(" ");
          }
          if (surr == 1) {
            lcd.setCursor(0, 1);
            lcd.print(" ");
            lcd.setCursor(5, 1);
            lcd.write(1);
          }
          break;

        case 2:
          lcd.setCursor(0, 0);
          lcd.print("Speaker Mode");
          lcd.setCursor(1, 1);
          lcd.print("5.1");
          lcd.setCursor(6, 1);
          lcd.print("2.1");
          if (speaker_mode == 0) {
            lcd.setCursor(0, 1);
            lcd.write(1);
            lcd.setCursor(5, 1);
            lcd.print(" ");
          }
          if (speaker_mode == 1) {
            lcd.setCursor(0, 1);
            lcd.print(" ");
            lcd.setCursor(5, 1);
            lcd.write(1);
          }
          break;

        case 3:
          lcd.setCursor(0, 0);
          lcd.print("-6dB");
          lcd.setCursor(1, 1);
          lcd.print("ON");
          lcd.setCursor(6, 1);
          lcd.print("OFF");
          if (mix == 0) {
            lcd.setCursor(0, 1);
            lcd.write(1);
            lcd.setCursor(5, 1);
            lcd.print(" ");
          }
          if (mix == 1) {
            lcd.setCursor(0, 1);
            lcd.print(" ");
            lcd.setCursor(5, 1);
            lcd.write(1);
          }
          break;

        case 4:
          lcd.setCursor(0, 0);
          lcd.print("All Reset");
          lcd.setCursor(1, 1);
          lcd.print("Reset");
          if (reset == 1) {
            lcd.setCursor(0, 1);
            lcd.write(1);
          }


          lcd.setCursor(0, 0);
          lcd.print("All Reset");
          lcd.setCursor(1, 1);
          lcd.print("Custom");
          lcd.setCursor(9, 1);
          lcd.print("Reset");
          if (reset == 0) {
            lcd.setCursor(0, 1);
            lcd.write(1);
            lcd.setCursor(8, 1);
            lcd.print(" ");
          }
          if (reset == 1) {
            lcd.setCursor(0, 1);
            lcd.print(" ");
            lcd.setCursor(8, 1);
            lcd.write(1);
          }
          break;
      }
      break;

    case 99:
      lcd.setCursor(0, 0);
      lcd.print("                ");
      lcd.setCursor(0, 1);
      lcd.print("      MUTE      ");
      break;

    case 100:
      lcd.setCursor(0, 0);
      lcd.print("                ");
      lcd.setCursor(0, 1);
      lcd.print("    STANDBY     ");
      break;
  }
  if (menu_active == 0) {
    int y;
    if (c < 0) {
      lcd.setCursor(8, 1);
      lcd.print("-");
      y = 10 - (c + 10);
    } else if (c == -10) {
      lcd.setCursor(8, 1);
      lcd.print("-");
      y = 10;
    } else {
      lcd.setCursor(8, 1);
      lcd.print(" ");
      y = c;
    }
    a = y / 10;
    b = y - a * 10;

    lcd.setCursor(9, 0);
    for (int i = 0; i < digit_width; i++)
      lcd.print(custom_num_top[a][i]);

    lcd.setCursor(9, 1);
    for (int i = 0; i < digit_width; i++)
      lcd.print(custom_num_bot[a][i]);

    lcd.setCursor(13, 0);
    for (int i = 0; i < digit_width; i++)
      lcd.print(custom_num_top[b][i]);

    lcd.setCursor(13, 1);
    for (int i = 0; i < digit_width; i++)
      lcd.print(custom_num_bot[b][i]);
  }

}

//all reset --------------------------------------------------------------------------------//

void set_reset() {
  if (reset == 1) {
    in = 0;
    mas_vol = 44;
    fl_vol = 0;
    fr_vol = 0;
    sl_vol = 0;
    sr_vol = 0;
    cn_vol = 0;
    sub_vol = 0;
    speaker_mode = 0;
    surr = 0;
    mix = 0;
    vol_menu = 0;
    menu_active = 0;
    reset = 0;
    lcd.clear();
  }
  set_in();
  set_fl();
  set_fr();
  set_sl();
  set_sr();
  set_cn();
  set_sub();
  set_speaker_mode();
  set_surr();
  set_mix();
}

//speaker mode --------------------------------------------------------------------------------//

void set_speaker_mode() {
  if (speaker_mode > 1) {
    speaker_mode = 0;
  }
  if (speaker_mode < 0) {
    speaker_mode = 1;
  }
  switch (speaker_mode) {
    case 0:                     // 5.1 mode
      ch_mute = 0;
      break;
    case 1:                     // 2.1 mode
      ch_mute = 1;
      break;
  }
  set_sl();
  set_sr();
  set_cn();
}

//AX2358 settings -----------------------------------------------------//

void set_in() {
  if (in > 4) {
    in = 0;
  }
  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 = 0b11001111; break; // 6 CH input
  }
  AX2358_send(a);
}
void set_surr() {
  if (surr > 1) {
    surr = 0;
  }
  if (surr < 0) {
    surr = 1;
  }
  switch (surr) {
    case 0: a = 0b11000000; break; // Surround ON
    case 1: a = 0b11000001; break; // Surround OFF
  }
  AX2358_send(a);
}
void set_mix() {
  if (mix > 1) {
    mix = 0;
  }
  switch (mix) {
    case 0: a = 0b11000010; break; // (-6dB) on
    case 1: a = 0b11000011; break; // (-6dB) off
  }
  AX2358_send(a);
}

//AX2358 Volume settings ----------------------------------------------//

void set_mas_vol() {
  if (mas_vol > 69) {
    mas_vol = 69;
  }
  if (mas_vol < 19) {
    mas_vol = 19;
  }
  if (mas_vol == 19) {
    mute = 1;
  } else {
    mute = 0;
  }
  set_mute();
}
void set_mute() {
  if (mute > 1) {
    mute = 0;
  }
  switch (mute) {
    case 0:                     // 5.1 mode
      ch_mute = 0;
      break;
    case 1:                     // 2.1 mode
      ch_mute = 1;
      break;
  }
  set_fl();
  set_fr();
  set_sub();
  if (speaker_mode == 0) {
    set_sl();
    set_sr();
    set_cn();
  }
}
void set_fl() {
  if (fl_vol > 10) {
    fl_vol = 10;
  }
  if (fl_vol < -10) {
    fl_vol = -10;
  }
  fl = mas_vol + fl_vol;
  int c = 79 - fl;
  a = c / 10;
  b = c - a * 10;
  AX2358_vol(0b10000000 + a, 0b10010000 + b);  // CH1
  
  switch (ch_mute) {
    case 0: x = 0b11110000; break; // Mute disabled
    case 1: x = 0b11110001; break; // Mute
  }
  AX2358_send(x);
}
void set_fr() {
  if (fr_vol > 10) {
    fr_vol = 10;
  }
  if (fr_vol < -10) {
    fr_vol = -10;
  }
  fr = mas_vol + fr_vol;
  int c = 79 - fr;
  a = c / 10;
  b = c - a * 10;
  AX2358_vol(0b01000000 + a, 0b01010000 + b);  // CH2

  switch (ch_mute) {
    case 0: x = 0b11110010; break; // Mute disabled
    case 1: x = 0b11110011; break; // Mute
  }
  AX2358_send(x);
}
void set_cn() {
  if (cn_vol > 10) {
    cn_vol = 10;
  }
  if (cn_vol < -10) {
    cn_vol = -10;
  }
  cn = mas_vol + cn_vol;
  int c = 79 - cn;
  a = c / 10;
  b = c - a * 10;
  AX2358_vol(0b00000000 + a, 0b00010000 + b);  // CH3

  switch (ch_mute) {
    case 0: x = 0b11110100; break; // Mute disabled
    case 1: x = 0b11110101; break; // Mute
  }
  AX2358_send(x);
}
void set_sub() {
  if (sub_vol > 10) {
    sub_vol = 10;
  }
  if (sub_vol < -10) {
    sub_vol = -10;
  }
  sub = mas_vol + sub_vol;
  int c = 79 - sub;
  a = c / 10;
  b = c - a * 10;
  AX2358_vol(0b00100000 + a, 0b00110000 + b);  // CH4

  switch (ch_mute) {
    case 0: x = 0b11110110; break; // Mute disabled
    case 1: x = 0b11110111; break; // Mute
  }
  AX2358_send(x);
}
void set_sl() {
  if (sl_vol > 10) {
    sl_vol = 10;
  }
  if (sl_vol < -10) {
    sl_vol = -10;
  }
  sl = mas_vol + sl_vol;
  int c = 79 - sl;
  a = c / 10;
  b = c - a * 10;
  AX2358_vol(0b01100000 + a, 0b01110000 + b);  // CH5

  switch (ch_mute) {
    case 0: x = 0b11111000; break; // Mute disabled
    case 1: x = 0b11111001; break; // Mute
  }
  AX2358_send(x);
}
void set_sr() {
  if (sr_vol > 10) {
    sr_vol = 10;
  }
  if (sr_vol < -10) {
    sr_vol = -10;
  }
  sr = mas_vol + sr_vol;
  int c = 79 - sr;
  a = c / 10;
  b = c - a * 10; 
  AX2358_vol(0b10100000 + a, 0b10110000 + b);  // CH6

  switch (ch_mute) {
    case 0: x = 0b11111010; break; // Mute disabled
    case 1: x = 0b11111011; break; // Mute
  }
  AX2358_send(x);
}

//AX2358 send -----------------------------------------------------//

void AX2358_send(char c) {
  Wire.beginTransmission(AX2358_address);
  Wire.write (c);
  Wire.endTransmission();
}
void AX2358() {
  Wire.beginTransmission(AX2358_address);
  Wire.write (0b11000100);
  Wire.endTransmission();
}
void AX2358_vol(char c, char d) {
  Wire.beginTransmission(AX2358_address);
  Wire.write (c);
  Wire.write (d);
  Wire.endTransmission();
}

//end code




Comments

popular posts

DIY Tutorial Resetting Toner Chip on Ricoh SP C250DN Printer in Simple Steps

  DIY Tutorial Resetting Toner Chip on Ricoh SP C250DN Printer in Simple Steps The RICOH SP 250DN printer toners have a chip that keeps track of the number of pages that have been printed. This is anoying because it will render a refill useless. In order to reuse this kind of toner, there are two things you need to do: refill the toner with ink (if needed) reset the toner chip (or replace it) There is plenty of information explaining how to refill the toner but little information on how to erase the toner chip. This document deals with the second point: how to dump the chip and reset it. It took me a while to get everything setup and to have my toner chip reset so I would like to share this process in order to help other to do the same with their printer toner cartridges. I will step through the process of understanding the problem, analysing the chip circuit, dumping the chip contents and writing back a pattern so the printer will be able to initialize the chip and set t...

DIY Metal Detector using Arduino A Simple Guide to Building Your Own at Home

  DIY Metal Detector using Arduino A Simple Guide to Building Your Own at Home How does a metal detector work? As we can see there are three things that are using to complete the whole project. Electronic circuit, Arduino, and a copper coil. here actually we are making a proximity sensor that detects the metal with a  metal detector  using Arduino . Here are the steps to build a DIY metal detector using an Arduino: Materials required: Arduino UNO Copper coil Diode 10nf capacitor Buzzer Led 220 ohm &  330 Ohm Resistor Jumper wires and a breadboard USB cable for uploading the code Circuit Diagram Arduino metal detector:-  Arduino UNO 10 nf Capacitor A2 Pin Terminal 1 GND Terminal 2 Arduino UNO Buzzer D6 Pin Positive GND  Negative Arduino LED 220 Ohm Resistor D5 Pin   Terminal 1   Anode Pin Terminal 2 GND Cathode Pin   Arduino UNO Copper coil Diode 330-ohm res   Terminal 1 Terminal 1 Terminal 1 A1 Pin     Terminal 2 A2 Pin ...

How to Calculate Inverter Battery Backup Time

  How to Calculate Inverter Battery Backup Time? Backup Time (in hours) = Battery Capacity (in Ah) X Input voltage (V) / Total Load (in Watts) Whenever you plan to buy an inverter battery, there is a desire to know some important information in your mind. Like how much will be the backup of the inverter battery, how many hours of backup will be available for how many ah batteries, etc. In this informative information, here you will know the backup time calculation formula.   Taking your inputs, you can calculate your total load, like: 3 tube led lights = 40 x 3 = 120 Watts 2 fans = 75 x 2 = 150 Watts 1 Bulb router = 1×20 Watts = 20 Watts So, the total load in your case is 120 + 150 + 20 = 290 Watts. Now, let us apply all these values in the above-said battery backup time formula.  Backup Time (in hours) = Battery Capacity (in Ah) X Input voltage (V) / Total Load (in Watts) Backup Time (in hours) = 150 x 12 / 290 = 6.2 So, your inverter battery will last around 6.2 hours ....

Wireless Joystick controlled Robot Car using Arduino, 433Mhz RF and L298N Motor Driver

    Wireless Joystick controlled Robot Car using Arduino – In this tutorial, you will learn how to control a Robot Car wirelessly using Arduino, L298N Motor driver, and  433 Mhz RF transmitter and Receiver . The robot control system can be activated and de-activated using the Built-in Joystick push Button. Arduino Uno Arduino Nano Mega 2560: Robot Car chassis kit: L298N motor driver: 2-Axis Analog Joystick 433 MHz Transmitter and Receiver Modules: DISCLAIMER: Please Note: these are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way! wireless joystick Interfacing: Watch this tutorial for the robot parts assembling and connections. All the connections are exactly the same as explained in my previous tutorial. The only modification that I did is the addition of the 433 Mhz RF receiver module…the VCC pin of the receiver module is connected with the 5 volts…the ground pin of the ...