From 80e15f3a6d136d3883bc03733db85ee708f31ff2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D0=BB=D0=B8=D0=BD=D0=B8=D0=BD=20=D0=A1=D0=B5?= =?UTF-8?q?=D1=80=D0=B3=D0=B5=D0=B9=20=D0=92=D0=B0=D0=BB=D0=B5=D1=80=D1=8C?= =?UTF-8?q?=D0=B5=D0=B2=D0=B8=D1=87?= Date: Mon, 30 Dec 2024 14:27:37 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20=D1=81=20?= =?UTF-8?q?=D1=80=D0=B5=D0=BB=D0=B5,=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=BE=20=D0=BC=D0=B5=D0=BD=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../control-panel-for-for-dac.ino | 344 ++++++++++++++++++ .../schematic_diagram_jX6yogu9qS.png | Bin .../vu-meter.png | Bin .../control-panel-for-for-dac.ino | 217 ----------- 4 files changed, 344 insertions(+), 217 deletions(-) create mode 100644 control-panel-for-for-dac/control-panel-for-for-dac.ino rename {dac_control_panel_code => control-panel-for-for-dac}/schematic_diagram_jX6yogu9qS.png (100%) rename {dac_control_panel_code => control-panel-for-for-dac}/vu-meter.png (100%) delete mode 100644 dac_control_panel_code/control-panel-for-for-dac.ino diff --git a/control-panel-for-for-dac/control-panel-for-for-dac.ino b/control-panel-for-for-dac/control-panel-for-for-dac.ino new file mode 100644 index 0000000..69ecff3 --- /dev/null +++ b/control-panel-for-for-dac/control-panel-for-for-dac.ino @@ -0,0 +1,344 @@ +// по материалам: +//https://www.instructables.com/Simple-LCD-MENU-Using-Arduino/ +// https://alexgyver.ru/lessons/ +// https://www.hackster.io/mircemk/diy-arduino-vfd-display-20x2-vu-volume-unit-meter-37898f + +#define GAIN 1 // усиление 0...50 +#define STEP 1 // плавность полос 0...20 +#define RL 1 // RL - горизонт, вертикаль 0...1 +// Выходы для управления реле (вкл.вкл ЦАП/Блютуз) +#define RELAY_POWER_USB 6 +#define RELAY_POWER_BT 7 +#define RELAY_POWER_MP3 10 +#define RELAY_OUT_USB 8 +#define RELAY_OUT_BT 9 +#define RELAY_OUT_MP3 11 + +// Кнопки +#define BTN_MENU 2 // Кнопка меню +#define BTN_EXECUTE 3 // Кнопка подтверждения +#define INIT_ADDR 1023 // номер резервной ячейки +#define INIT_KEY 1 // ключ первого запуска + +//#include +#include +#include +#include + +// LiquidCrystal lcdVuMeter(2, 3, 4, 5, 6, 7);// RS,E,D4,D5,D6,D7 +LiquidCrystal_I2C lcdVuMeter(0x27, 16, 2); +LiquidCrystal_I2C lcdService(0x26, 16, 2); + +byte z,z0,z1,w,www=1; +int ur,ul,urr,ull,urrr,ulll; +int x,i,u_maxr,u_maxl; +int u_l0[20],u_r0[20]; +bool usb, bluetooth, mp3; +int menu = 1; +bool menuShow = false; + +void setup() { + pinMode(8,INPUT_PULLUP); + byte znak_r[8]={0b00000,0b00000,0b11111,0b00101,0b00101,0b11010,0b00000,0b00000}; + byte znak_l[8]={0b00000,0b00000,0b11111,0b10000,0b10000,0b10000,0b00000,0b00000}; + lcdVuMeter.init(); + lcdVuMeter.backlight(); + lcdVuMeter.clear(); + lcdVuMeter.setCursor(0, 0); + lcdVuMeter.print("R"); +// lcdVuMeter.createChar(4,znak_r); + lcdVuMeter.setCursor(0, 1); + lcdVuMeter.print("L"); + lcdService.init(); + lcdService.backlight(); + lcdService.clear(); + // lcdService.setCursor(0, 0); +// lcdService.print("Menu"); + +// Кнопка управления (переключения) + pinMode(BTN_MENU, INPUT_PULLUP); + pinMode(BTN_EXECUTE, INPUT_PULLUP); +// Выходы для управления реле (вкл.вкл ЦАП/Блютуз) + pinMode(RELAY_POWER_USB, OUTPUT); + pinMode(RELAY_POWER_BT, OUTPUT); + pinMode(RELAY_POWER_MP3, OUTPUT); + pinMode(RELAY_OUT_USB, OUTPUT); + pinMode(RELAY_OUT_BT, OUTPUT); + pinMode(RELAY_OUT_MP3, OUTPUT); + + // lcdVuMeter.createChar(5,znak_l); + // lcdVuMeter.begin(16, 2);// lcdVuMeter 16X2 + // analogReference(INTERNAL); // если очень маленький уровень сигнала + pinMode(A0,INPUT);// A0 - аналоговый вход R + pinMode(A1,INPUT);// A1 - аналоговый вход L + + // первый запуск и установка занчений переменных в память + if (EEPROM.read(INIT_ADDR) != INIT_KEY) { + EEPROM.write(INIT_ADDR, INIT_KEY); + usb = true; + bluetooth = false; + mp3 = false; + + EEPROM.put(10, usb); + EEPROM.put(12, bluetooth); + EEPROM.put(14, mp3); + } else { + usb = EEPROM.read(10); + bluetooth = EEPROM.read(12); + mp3 = EEPROM.read(14); + } + + w = EEPROM.read(0); + + + updateMenu(); +} + +void vu_metter() { + + if(digitalRead(8)==LOW){w++;www=1;if(w>4){w=0;}delay(200);EEPROM.update(0,w);} + + if(w==0&&www==1){www=0; + byte a1[8] = {0b10101,0b10101,0b10101,0b10101,0b10101,0b10101,0b10101,0b10101}; + byte a2[8] = {0b10100,0b10100,0b10100,0b10100,0b10100,0b10100,0b10100,0b10100}; + byte a3[8] = {0b10000,0b10000,0b10000,0b10000,0b10000,0b10000,0b10000,0b10000}; + byte a4[8] = {0b00011,0b00011,0b00011,0b0011,0b0011,0b0011,0b0011,0b0011};// + lcdVuMeter.createChar(0,a1);lcdVuMeter.createChar(1,a2);lcdVuMeter.createChar(2,a3);lcdVuMeter.createChar(6,a4);} + if(w==1&&www==1){www=0; + byte a1[8] = {0b00000,0b10101,0b10101,0b10101,0b10101,0b10101,0b10101,0b00000}; + byte a2[8] = {0b00000,0b10100,0b10100,0b10100,0b10100,0b10100,0b10100,0b00000}; + byte a3[8] = {0b00000,0b10000,0b10000,0b10000,0b10000,0b10000,0b10000,0b00000}; + byte a4[8] = {0b00000,0b0011,0b0011,0b0011,0b0011,0b0011,0b0011,0b00000};// + lcdVuMeter.createChar(0,a1);lcdVuMeter.createChar(1,a2);lcdVuMeter.createChar(2,a3);lcdVuMeter.createChar(6,a4);} + if(w==2&&www==1){www=0; + byte a1[8] = {0b10101,0b10101,0b10101,0b00000,0b00000,0b10101,0b10101,0b10101}; + byte a2[8] = {0b10100,0b10100,0b10100,0b00000,0b00000,0b10100,0b10100,0b10100}; + byte a3[8] = {0b10000,0b10000,0b10000,0b00000,0b00000,0b10000,0b10000,0b10000}; + byte a4[8] = {0b0011,0b0011,0b0011,0b0011,0b0011,0b0011,0b0011,0b0011}; + lcdVuMeter.createChar(0,a1);lcdVuMeter.createChar(1,a2);lcdVuMeter.createChar(2,a3);lcdVuMeter.createChar(6,a4);} + if(w==3&&www==1){www=0; + byte a1[8] = {0b00000,0b10101,0b10101,0b00000,0b00000,0b10101,0b10101,0b00000}; + byte a2[8] = {0b00000,0b10100,0b10100,0b00000,0b00000,0b10100,0b10100,0b00000}; + byte a3[8] = {0b00000,0b10000,0b10000,0b00000,0b00000,0b10000,0b10000,0b00000}; + byte a4[8] = {0b00000,0b0011,0b0011,0b0011,0b0011,0b0011,0b0011,0b00000}; + lcdVuMeter.createChar(0,a1);lcdVuMeter.createChar(1,a2);lcdVuMeter.createChar(2,a3);lcdVuMeter.createChar(6,a4);} + if(w==4&&www==1){www=0; + byte a1[8] = {0b00000,0b00000,0b10101,0b10101,0b10101,0b10101,0b00000,0b00000}; + byte a2[8] = {0b00000,0b00000,0b10100,0b10100,0b10100,0b10100,0b00000,0b00000}; + byte a3[8] = {0b00000,0b00000,0b10000,0b10000,0b10000,0b10000,0b00000,0b00000}; + byte a4[8] = {0b00000,0b00000,0b0011,0b0011,0b0011,0b0011,0b00000,0b00000}; + lcdVuMeter.createChar(0,a1);lcdVuMeter.createChar(1,a2);lcdVuMeter.createChar(2,a3);lcdVuMeter.createChar(6,a4);} + + urr = log(analogRead(0))*GAIN;if(urr>41){urr=41;} + ull = log(analogRead(1))*GAIN;if(ull>41){ull=41;} + + if(RL==0){lcdVuMeter.setCursor(0,0);lcdVuMeter.write((uint8_t)4);lcdVuMeter.setCursor(0,1);lcdVuMeter.write((uint8_t)5);} + if(RL==1){lcdVuMeter.setCursor(0,1);lcdVuMeter.print("L");lcdVuMeter.setCursor(0,0);lcdVuMeter.print("R");} + + if(urr2){z1=0;z0++;} + if(z1==1){lcdVuMeter.setCursor(z0+1,1);lcdVuMeter.write((uint8_t)0);lcdVuMeter.setCursor(z0+2,1);if(ur<39){lcdVuMeter.print(" ");}}} + if(z1==3){lcdVuMeter.setCursor(z0+1,1);lcdVuMeter.write((uint8_t)1);} + if(z1==2){lcdVuMeter.setCursor(z0+1,1);lcdVuMeter.write((uint8_t)2);} + + if(ull2){z1=0;z0++;} + if(z1==1){lcdVuMeter.setCursor(z0+1,0);lcdVuMeter.write((uint8_t)0);lcdVuMeter.setCursor(z0+2,0);if(ul<39){lcdVuMeter.print(" ");}}} + if(z1==3){lcdVuMeter.setCursor(z0+1,0);lcdVuMeter.write((uint8_t)1);} + if(z1==2){lcdVuMeter.setCursor(z0+1,0);lcdVuMeter.write((uint8_t)2);} + +////////////////////////////////////////////////////////// + +i++;if(i<19){u_l0[i]=abs(ull);u_r0[i]=abs(urr);}else{i=1;} + if(i==18){u_maxr=0;u_maxl=0; + for(x=1;x<=15;x++){ + u_maxl=max(u_maxl,u_l0[x]); + u_maxr=max(u_maxr,u_r0[x]);}} + + if(u_maxl<=ull){u_maxl=ull+1;} + if(u_maxr<=urr){u_maxr=urr+1;} + + if(u_maxl2){lcdVuMeter.write((uint8_t)6);}lcdVuMeter.print(" "); + lcdVuMeter.setCursor(urrr/3+1,1);if(urrr/3>2){lcdVuMeter.write((uint8_t)6);}lcdVuMeter.print(" "); + delay(3); +} + +String setUSBinput() { + return "USB input"; +} + + +void updateMenu() { + switch (menu) { + case 0: + menu = 1; + break; + case 1: + lcdService.clear(); + lcdService.print(">USB DAC"); + lcdService.setCursor(2, 1); + if(usb){ + lcdService.print("On"); + }else{ + lcdService.print("Off"); + } + break; + case 2: + lcdService.clear(); + lcdService.print(">Bluetooth"); + lcdService.setCursor(2, 1); + if(bluetooth){ + lcdService.print("On"); + }else{ + lcdService.print("Off"); + } + break; + case 3: + lcdService.clear(); + lcdService.print(">MP3 module"); + lcdService.setCursor(2, 1); + if(mp3){ + lcdService.print("On"); + }else{ + lcdService.print("Off"); + } + break; + case 4: + menu = 0; + menuShow = false; + lcdService.clear(); + break; + } +} + +void executeMenuAction() { + switch (menu) { + case 1: + actionUSB(); + break; + case 2: + actionBT(); + break; + case 3: + actionMP3(); + break; + } + EEPROM.put(10, usb); + EEPROM.put(12, bluetooth); + EEPROM.put(14, mp3); +} + +void actionUSB() { +// lcdService.clear(); + lcdService.setCursor(2,1); + lcdService.print("On "); + digitalWrite(RELAY_POWER_BT,LOW); + digitalWrite(RELAY_POWER_MP3,LOW); + + digitalWrite(RELAY_OUT_BT,LOW); + digitalWrite(RELAY_OUT_MP3,LOW); + delay(1000); + digitalWrite(RELAY_OUT_USB,HIGH); + digitalWrite(RELAY_POWER_USB,HIGH); + usb = true; + bluetooth = false; + mp3 = false; + + delay(1500); +} + +void actionBT() { +// lcdService.clear(); + lcdService.setCursor(2,1); + lcdService.print("On "); + digitalWrite(RELAY_POWER_USB,LOW); + digitalWrite(RELAY_POWER_MP3,LOW); + + digitalWrite(RELAY_OUT_USB,LOW); + digitalWrite(RELAY_OUT_MP3,LOW); + delay(1000); + digitalWrite(RELAY_OUT_BT,HIGH); + digitalWrite(RELAY_POWER_BT,HIGH); + usb = false; + bluetooth = true; + mp3 = false; + + delay(1500); +} + +void actionMP3() { +// lcdService.clear(); + lcdService.setCursor(2,1); + lcdService.print("On "); + digitalWrite(RELAY_POWER_USB,LOW); + digitalWrite(RELAY_POWER_BT,LOW); + + digitalWrite(RELAY_OUT_USB,LOW); + digitalWrite(RELAY_OUT_BT,LOW); + delay(1000); + digitalWrite(RELAY_OUT_MP3,HIGH); + digitalWrite(RELAY_POWER_MP3,HIGH); + usb = false; + bluetooth = false; + mp3 = true; + delay(1500); +} + +uint32_t btnTimer = 0; + +void loop() { + lcdService.setCursor(0,0); + // Выводим на экран информацию какой модуль включен + + if(!menuShow){ + if(usb){ + lcdService.print("USB DAC"); + lcdService.setCursor(0,1); + lcdService.print(setUSBinput()); + } + if(bluetooth){ + lcdService.print("Bluetooth"); + } + if(mp3){ + lcdService.print("MP3 module"); + } + } +// bool btnMenuState = digitalRead(BTN_MENU); +// bool btnExecuteState = digitalRead(BTN_EXECUTE); + + if (!digitalRead(BTN_MENU)){ + menuShow = true; + menu ++; + updateMenu(); + delay(100); + while (!digitalRead(BTN_MENU)); + } + if (!digitalRead(BTN_EXECUTE)){ + executeMenuAction(); + updateMenu(); + delay(100); + while (!digitalRead(BTN_EXECUTE)); + } +// Тут будет код обработки данных от USB DAC для индикации режима его работы +// if (digitalRead(8) && usb) { +// lcdService.setCursor(0,1); +// lcdService.print("Coaxial"); +// } else if (digitalRead(9) && usb) { +// lcdService.setCursor(0,1); +// lcdService.print("Optical"); +// } else if (digitalRead(10) && usb) { +// lcdService.setCursor(0,1); +// lcdService.print("Audio "); +// } else { +// lcdService.setCursor(0,1); +// lcdService.print(" "); +// } +// lcdService.setCursor(11,1); +// lcdService.print(digitalRead(8), digitalRead(9)); + + vu_metter(); +} diff --git a/dac_control_panel_code/schematic_diagram_jX6yogu9qS.png b/control-panel-for-for-dac/schematic_diagram_jX6yogu9qS.png similarity index 100% rename from dac_control_panel_code/schematic_diagram_jX6yogu9qS.png rename to control-panel-for-for-dac/schematic_diagram_jX6yogu9qS.png diff --git a/dac_control_panel_code/vu-meter.png b/control-panel-for-for-dac/vu-meter.png similarity index 100% rename from dac_control_panel_code/vu-meter.png rename to control-panel-for-for-dac/vu-meter.png diff --git a/dac_control_panel_code/control-panel-for-for-dac.ino b/dac_control_panel_code/control-panel-for-for-dac.ino deleted file mode 100644 index 03197c0..0000000 --- a/dac_control_panel_code/control-panel-for-for-dac.ino +++ /dev/null @@ -1,217 +0,0 @@ -// https://www.hackster.io/mircemk/diy-arduino-vfd-display-20x2-vu-volume-unit-meter-37898f -// #include -#include - -// Выходы для управления реле (вкл.вкл ЦАП/Блютуз) -#define RELAY_DAC 6 -#define RELAY_BT 7 - -// LiquidCrystal lcdVuMeterVuMeter(12, 11, 5, 4, 3, 2);// RS,E,D4,D5,D6,D7 -LiquidCrystal_I2C lcdVuMeter(0x26, 16, 2); -LiquidCrystal_I2C lcdInfo(0x27, 16, 2); - -byte a1[8]={ - 0b00000,0b11011,0b11011,0b11011,0b11011,0b11011,0b11011,0b11011}; -byte a2[8]={ - 0b00000,0b11000,0b11000,0b11000,0b11000,0b11000,0b11000,0b11000}; -byte a3[8]={ - 0b00000,0b00011,0b00011,0b00011,0b00011,0b00011,0b00011,0b00011}; -byte znak_r[8]={ // R - B00000, - B11100, - B10010, - B10010, - B11100, - B11000, - B10100, - B10010}; -byte znak_l[8]={ // L - B00000, - B10000, - B10000, - B10000, - B10000, - B10000, - B10000, - B11110}; -int u_r,u_l,i=1,x,u_maxr,u_maxl,z,z1,u_r0[15],u_l0[15]; -unsigned long time1; -long decayTime = 0; -void setup(){ - analogReference(INTERNAL); - lcdVuMeter.init(); - lcdVuMeter.backlight(); - lcdVuMeter.clear(); - lcdVuMeter.setCursor(0, 0); -// lcdVuMeter.begin(16, 2);// lcdVuMeter 16X2 - lcdVuMeter.createChar(0,a1); - lcdVuMeter.createChar(1,a2); - lcdVuMeter.createChar(2,znak_r); - lcdVuMeter.createChar(3,znak_l); - lcdVuMeter.createChar(4,a3); - - lcdInfo.init(); - lcdInfo.backlight(); - lcdInfo.clear(); - lcdInfo.setCursor(0, 0); - lcdInfo.print("DAC"); - -// Вход аудио-сигнала - pinMode(A0,INPUT); - pinMode(A1,INPUT); - -// Кнопка управления (переключения) - pinMode(3, INPUT_PULLUP); - pinMode(8, INPUT_PULLUP); - pinMode(9, INPUT_PULLUP); - pinMode(10, INPUT_PULLUP); -// Выходы для управления реле (вкл.вкл ЦАП/Блютуз) - pinMode(RELAY_DAC, OUTPUT); - pinMode(RELAY_BT, OUTPUT); - - digitalWrite(RELAY_DAC, HIGH); - - lcdVuMeter.clear(); -// lcdVuMeter.setCursor(5, 0); -// lcdVuMeter.print("Loading..."); - -// for (int i = 0; i < 20; i++) -// { -// lcdVuMeter.setCursor(i, 1); -// lcdVuMeter.write(1); -// -// delay(100); -// } - - delay(5); - lcdVuMeter.clear(); - - decayTime = millis(); -} - -bool usb = true; -bool blueTooth = false; -uint32_t btnTimer = 0; -void loop(){ - lcdVuMeter.setCursor(0,0);// R - lcdVuMeter.write((uint8_t)2); - lcdVuMeter.setCursor(0,1); - lcdVuMeter.write((uint8_t)3);// L - - u_r = analogRead(A0); // измерение R - u_l = analogRead(A2); // измерение L - - for(int z=1,z1=0,z2=30;z<=15;z++,z1=z1+30,z2=z2+30){ // l+r - if(u_l>z1){ - lcdVuMeter.setCursor(z,1); - lcdVuMeter.write((uint8_t)1); - } - if(u_r>z1){ - lcdVuMeter.setCursor(z,0); - lcdVuMeter.write((uint8_t)1); - } - if(u_l>z2){ - lcdVuMeter.setCursor(z,1); - lcdVuMeter.write((uint8_t)0); - } - if(u_r>z2){ - lcdVuMeter.setCursor(z,0); - lcdVuMeter.write((uint8_t)0); - } - } - - i++; - if(i<=15){ - u_l0[i]=u_l; - u_r0[i]=u_r; - } - else{ - i=1; - } - if(i==15){ - u_maxr=0; - u_maxl=0; - for(x=1;x<=15;x++){ - u_maxl=max(u_maxl,u_l0[x]); - u_maxr=max(u_maxr,u_r0[x]); - } - } - - if(u_maxl<=u_l){ - u_maxl=u_l; - } - if(u_maxr<=u_r){ - u_maxr=u_r; - } -// -// for(z=1,z1=0;z<=15;z++,z1=z1+30){ -// if(u_maxl > z1 && u_maxl <= z1+15){ -// lcdVuMeter.setCursor(z,1); -// lcdVuMeter.write((uint8_t)1); -// } -// if(u_maxl > z1+15 && u_maxl <= z1+30){ -// lcdVuMeter.setCursor(z,1); -// lcdVuMeter.write((uint8_t)4); -// } -// -// if(u_maxr > z1 && u_maxr <= z1+15){ -// lcdVuMeter.setCursor(z,0); -// lcdVuMeter.write((uint8_t)1); -// } -// if(u_maxr > z1+15 && u_maxr <= z1+30){ -// lcdVuMeter.setCursor(z,0); -// lcdVuMeter.write((uint8_t)4); -// } -// } - delay(30); - lcdVuMeter.clear(); - - // читаем инвертированное значение для удобства - bool btnState = digitalRead(3); - if (btnState&& millis() - btnTimer > 100) { // обработчик нажатия - lcdInfo.clear(); - if (!usb && blueTooth) { - usb = true; - blueTooth = false; - btnTimer = millis(); - lcdInfo.setCursor(0,0); - lcdInfo.print("DAC"); - delay(1000); - digitalWrite(RELAY_BT, LOW); - digitalWrite(RELAY_DAC, HIGH); - } else if (usb && !blueTooth&& millis() - btnTimer > 100) { - usb = false; - blueTooth = true; - btnTimer = millis(); - lcdInfo.setCursor(0,0); - lcdInfo.print("Bluetooth"); - delay(1000); - digitalWrite(RELAY_DAC, LOW); - digitalWrite(RELAY_BT, HIGH); - } - lcdInfo.setCursor(0,1); -// lcdInfo.print(btnState); - } - - if (digitalRead(8) && usb) { - lcdInfo.setCursor(0,1); - lcdInfo.print("Coaxial"); - } else if (digitalRead(9) && usb) { - lcdInfo.setCursor(0,1); - lcdInfo.print("Optical"); - } else if (digitalRead(10) && usb) { - lcdInfo.setCursor(0,1); - lcdInfo.print("Audio "); - } else { - lcdInfo.setCursor(0,1); - lcdInfo.print(" "); - } - lcdInfo.setCursor(11,1); - lcdInfo.print(digitalRead(8), digitalRead(9)); -// if (!btnState) { // обработчик отпускания -// lcdInfo.clear(); -// lcdInfo.setCursor(0,1); -// lcdInfo.print(btnState); -// //Serial.println("release"); -// } -}