Feat: add button for deepsleed and resistor for volume
This commit is contained in:
parent
dc739f6408
commit
eee30401a8
@ -6,23 +6,27 @@
|
||||
#define I2S_DOUT 25
|
||||
#define I2S_BCLK 27
|
||||
#define I2S_LRC 26
|
||||
#define STATUSLED 32
|
||||
#define POWERBUTTON GPIO_NUM_33
|
||||
#define VOLUMERES 34
|
||||
Audio audio;
|
||||
wifi_config_t wifi_config = {0};
|
||||
|
||||
String ssid = WIFI_SSID;
|
||||
String password = WIFI_PASSWD;
|
||||
String hostname = HOSTNAME;
|
||||
|
||||
int analogValue;
|
||||
int volumeresistor;
|
||||
int powerButtonState = 0;
|
||||
|
||||
void setup() {
|
||||
pinMode(STATUSLED, OUTPUT);
|
||||
pinMode(POWERBUTTON, INPUT);
|
||||
|
||||
wifi_init();
|
||||
Serial.println(".");
|
||||
Serial.println("WiFi connecte");
|
||||
Serial.println("Adresse IP: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
Serial.println(WiFi.RSSI());
|
||||
wifi_info();
|
||||
|
||||
esp_sleep_enable_ext0_wakeup(POWERBUTTON, 1);
|
||||
|
||||
audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
|
||||
audio.setVolume(30);
|
||||
@ -30,21 +34,42 @@ void setup() {
|
||||
audio.connecttohost("http://icecast.radiofrance.fr/franceinter-midfi.mp3");
|
||||
// audio.connecttohost("0n-80s.radionetz.de:8000/0n-70s.mp3");
|
||||
|
||||
|
||||
}
|
||||
|
||||
void 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() {
|
||||
Serial.begin(115200);
|
||||
digitalWrite(STATUSLED, HIGH);
|
||||
WiFi.disconnect();
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.setHostname(hostname.c_str());
|
||||
@ -54,8 +79,11 @@ void wifi_init() {
|
||||
Serial.println(ssid);
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(1500);
|
||||
digitalWrite(STATUSLED, LOW);
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
digitalWrite(STATUSLED, HIGH);
|
||||
delay(500);
|
||||
}
|
||||
WiFi.config(WiFi.localIP(), WiFi.gatewayIP(), WiFi.subnetMask(), IPAddress(192,168,2,1));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user