Skip to content

Instantly share code, notes, and snippets.

@maxpromer
Created February 26, 2026 08:26
Show Gist options
  • Select an option

  • Save maxpromer/798c7ecaaf6c2e8d2bc0f19469bcca75 to your computer and use it in GitHub Desktop.

Select an option

Save maxpromer/798c7ecaaf6c2e8d2bc0f19469bcca75 to your computer and use it in GitHub Desktop.
#include "Arduino.h"
#include "WiFi.h"
#include "Audio.h"
// ─── กำหนดขา I2S ───────────────────────────────────────
#define I2S_BCK_PIN 26
#define I2S_WS_PIN 25
#define I2S_DATA_PIN 22
// ─── ข้อมูล Wi-Fi ────────────────────────────────────────
#define WIFI_SSID "Your_SSID"
#define WIFI_PASSWORD "Your_Password"
Audio audio;
void setup() {
Serial.begin(115200);
// ─── เชื่อมต่อ Wi-Fi ─────────────────────────────────
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nWiFi Connected!");
// ─── ตั้งค่า I2S ─────────────────────────────────────
audio.setPinout(I2S_BCK_PIN, I2S_WS_PIN, I2S_DATA_PIN);
audio.setVolume(15); // ระดับเสียง 0 – 21
// ─── เล่นไฟล์ MP3 จาก URL ────────────────────────────
audio.connecttohost("http://your-stream-url.com/audio.mp3");
}
void loop() {
audio.loop(); // ต้องเรียกทุก loop เพื่อให้เสียงเล่นต่อเนื่อง
}
// ─── Callback: แสดงข้อมูลเพลง ────────────────────────────
void audio_info(const char *info) {
Serial.print("Info: ");
Serial.println(info);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment