Тема: Pt2257 + энкодер+ lcd1602 i2c+ ИК пульт
Помогите переделать ваш скетч под комплектующие.
#include <Wire.h>
#include <EEPROMex.h>
#include <PT2257.h>
#include <LiquidCrystal.h>
PT2257 rt;
#include <Encoder.h>
Encoder myEnc(10, 11);//CLK, DT
LiquidCrystal lcd(7, 6, 2, 3, 4, 5);// RS,E,D4,D5,D6,D7
int menu,vol,vol_ram,vol_d,z,balans,balans_ram,balans_d,z1;
byte w,mute;
long oldPosition = -999;
unsigned long time,time1;
byte a1[8]={0b00000,0b00000,0b11011,0b11011,0b11011,0b11011,0b00000,0b00000};
byte a2[8]={0b00000,0b00000,0b11000,0b11000,0b11000,0b11000,0b00000,0b00000};
byte a3[8]={0b00000,0b00000,0b00000,0b11011,0b11011,0b00000,0b00000,0b00000};
byte a4[8]={0b00000,0b00000,0b00000,0b11000,0b11000,0b00000,0b00000,0b00000};
void setup() {
Wire.begin();Serial.begin(9600);lcd.begin(16, 2);
pinMode(12,INPUT);// кнопка энкодера
pinMode(A0,INPUT);// кнопка mute
lcd.createChar(0,a1); lcd.createChar(1,a2);lcd.createChar(2,a3); lcd.createChar(3,a4);
vol = EEPROM.read(0);// vol eeprom
balans = EEPROM.read(1)-7;
vol_ram=vol;balans_ram=balans;
delay(1000);
audio();
}
void loop() {
if(digitalRead(12)==LOW){menu++;myEnc.write(0);vol_ram=vol;balans_ram=balans;delay(300);if(menu>1||menu<0){menu=0;}}
/////////////////////////////////////// vol /////////////////////////////////////
if(menu==0){
long newPosition = myEnc.read()/4+vol_ram;
if (newPosition != oldPosition) {
oldPosition = newPosition;vol=newPosition;
audio();time = millis();w=1;
if(vol>79){myEnc.write(0);vol_ram=79;}
if(vol<0){myEnc.write(0);vol_ram=0;}
}}
// индикация баланс + управление кнопками +\- 4 дБ ///////
if(menu==1){
long newPosition = myEnc.read()/4+balans_ram;
if (newPosition != oldPosition) {
oldPosition = newPosition;balans=newPosition;
audio();time = millis();w=1;
if(balans>7){myEnc.write(0);balans_ram=7;}
if(balans<-7){myEnc.write(0);balans_ram=-7;}
}}
/////////////////////////////////////////////////////////////
if(millis()-time1>100){lcd.clear();vol_d=vol/3;
if(vol_d>=0){for(z=0;z<=vol_d;z++){lcd.setCursor(z/2,0);if(menu==0){lcd.write((uint8_t)0);}else{lcd.write((uint8_t)2);}}}
if((vol_d)%2==0){lcd.setCursor(z/2,0);if(menu==0){lcd.write((uint8_t)1);}else{lcd.write((uint8_t)3);}}
lcd.setCursor(14,0);lcd.print(vol);time1=millis();
if(balans<0){lcd.setCursor(balans+7,1);if(menu==1){lcd.write((uint8_t)0);}else{lcd.write((uint8_t)2);}}
if(balans>0){lcd.setCursor(balans+8,1);if(menu==1){lcd.write((uint8_t)0);}else{lcd.write((uint8_t)2);}}
if(balans==0){lcd.setCursor(7,1);if(menu==1){lcd.write((uint8_t)0);}else{lcd.write((uint8_t)2);}lcd.setCursor(8,1);
if(menu==1){lcd.write((uint8_t)0);}else{lcd.write((uint8_t)2);}}else{lcd.setCursor(7,1);if(balans>0){lcd.print("+");}lcd.print(balans);}
}
///////////// mute ////////////////////////////////
if(analogRead(A1)>900){mute++;delay(300);if(mute>1){mute=0;}audio();}
///////////// eeprom //////////////////////////////
if(millis()-time>10000 && w==1){// запись всех настроек в EEPROM через 60 сек неактивности
EEPROM.update(0,vol);EEPROM.update(1,balans+7); w=0;}
}
void audio(){
rt.setLeft(vol-8+balans); // int 0...79
rt.setRight(vol-8-balans);// int 0...79
rt.setMute(mute); // int 0...1
}