Feat: add button for deepsleed and resistor for volume

This commit is contained in:
Bertrand Benjamin 2022-08-15 15:06:27 +02:00
parent dc739f6408
commit eee30401a8
1 changed files with 39 additions and 11 deletions

View File

@ -6,23 +6,27 @@
#define I2S_DOUT 25 #define I2S_DOUT 25
#define I2S_BCLK 27 #define I2S_BCLK 27
#define I2S_LRC 26 #define I2S_LRC 26
#define STATUSLED 32
#define POWERBUTTON GPIO_NUM_33
#define VOLUMERES 34
Audio audio; Audio audio;
wifi_config_t wifi_config = {0};
String ssid = WIFI_SSID; String ssid = WIFI_SSID;
String password = WIFI_PASSWD; String password = WIFI_PASSWD;
String hostname = HOSTNAME; String hostname = HOSTNAME;
int analogValue; int volumeresistor;
int powerButtonState = 0;
void setup() { void setup() {
pinMode(STATUSLED, OUTPUT);
pinMode(POWERBUTTON, INPUT);
wifi_init(); wifi_init();
Serial.println("."); wifi_info();
Serial.println("WiFi connecte");
Serial.println("Adresse IP: ");
Serial.println(WiFi.localIP());
Serial.println(WiFi.RSSI());
esp_sleep_enable_ext0_wakeup(POWERBUTTON, 1);
audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT); audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
audio.setVolume(30); audio.setVolume(30);
@ -30,21 +34,42 @@ void setup() {
audio.connecttohost("http://icecast.radiofrance.fr/franceinter-midfi.mp3"); audio.connecttohost("http://icecast.radiofrance.fr/franceinter-midfi.mp3");
// audio.connecttohost("0n-80s.radionetz.de:8000/0n-70s.mp3"); // audio.connecttohost("0n-80s.radionetz.de:8000/0n-70s.mp3");
} }
void loop() void loop()
{ {
audio.loop(); audio.loop();
volumeAdjust();
powerButton();
analogValue = analogRead(34); }
audio.setVolume(analogValue*30/4095);
void volumeAdjust () {
volumeresistor = analogRead(VOLUMERES);
// Serial.println(volumeresistor);
audio.setVolume(volumeresistor*30/4095);
}
void powerButton () {
powerButtonState = digitalRead(POWERBUTTON);
if (powerButtonState == 1) {
Serial.println("Deepsleep mod");
delay(500);
esp_deep_sleep_start();
}
}
void wifi_info() {
Serial.println(".");
Serial.println("WiFi connecte");
Serial.println("Adresse IP: ");
Serial.println(WiFi.localIP());
} }
void wifi_init() { void wifi_init() {
Serial.begin(115200); Serial.begin(115200);
digitalWrite(STATUSLED, HIGH);
WiFi.disconnect(); WiFi.disconnect();
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
WiFi.setHostname(hostname.c_str()); WiFi.setHostname(hostname.c_str());
@ -54,8 +79,11 @@ void wifi_init() {
Serial.println(ssid); Serial.println(ssid);
while (WiFi.status() != WL_CONNECTED) { while (WiFi.status() != WL_CONNECTED) {
delay(1500); digitalWrite(STATUSLED, LOW);
delay(500);
Serial.print("."); Serial.print(".");
digitalWrite(STATUSLED, HIGH);
delay(500);
} }
WiFi.config(WiFi.localIP(), WiFi.gatewayIP(), WiFi.subnetMask(), IPAddress(192,168,2,1)); WiFi.config(WiFi.localIP(), WiFi.gatewayIP(), WiFi.subnetMask(), IPAddress(192,168,2,1));