/*
* ————————————————————
* 1-Wire Voice Playback IC Controller
* ————————————————————
* This code communicates with a voice playback IC
* KT148 using a single data line from Arduino.
*
* Supported commands:
* 1. Play a specific audio track once
* 2. Play a specific audio track in loop
* 3. Play a combination of multiple audio tracks sequentially
* 4. Enter low-power (sleep) mode
* 5. Wake from low-power mode
*
* Author: [UGE Electronics]
* UGE-ONE.COM
* ————————————————————
*/
#define DATA_PIN 5 // Single-wire data pin connected to voice IC
// ————————————————————
// Initialization
// ————————————————————
void setup() {
pinMode(DATA_PIN, OUTPUT);
digitalWrite(DATA_PIN, HIGH); // Idle state is HIGH
Serial.begin(115200);
delay(1000);
Serial.println(“Voice Playback Test Begin!”);
Serial.println(“Playing tracks 0x01, 0x02, 0x03 in sequence…”);
Combo_Play(0x01, 0x02, 0x03);
digitalWrite(DATA_PIN, HIGH); // Ensure high level for next command
}
void loop() {
// Empty loop – commands can be called from here as needed
}
// ————————————————————
// Low-level 1-wire data transmission
// ————————————————————
/**
* @brief Send one byte of data to the voice IC.
*
* @param dat The data byte to send.
*/
void oneWireWrite(uint8_t dat) {
digitalWrite(DATA_PIN, LOW);
delay(6); // Start condition
for (int i = 0; i < 8; i++) {
if (dat & 0x01) {
// Send bit ‘1’ pulse
digitalWrite(DATA_PIN, HIGH);
delayMicroseconds(600);
digitalWrite(DATA_PIN, LOW);
delayMicroseconds(200);
} else {
// Send bit ‘0’ pulse
digitalWrite(DATA_PIN, HIGH);
delayMicroseconds(200);
digitalWrite(DATA_PIN, LOW);
delayMicroseconds(600);
}
dat >>= 1;
}
digitalWrite(DATA_PIN, HIGH); // Return to idle
}
// ————————————————————
// High-level command functions
// ————————————————————
/**
* @brief Play a specific audio file once.
*
* @param address The audio file address (e.g. 0x01 for first track).
*/
void Play(uint8_t address) {
oneWireWrite(address);
delay(20);
}
/**
* @brief Loop a specific audio file continuously.
*
* @param address The audio file address.
*/
void Loop_Play(uint8_t address) {
oneWireWrite(address);
delay(20);
oneWireWrite(0xF2); // 0xF2 = Loop command
delay(20);
}
/**
* @brief Play a combination of three audio files sequentially.
*
* @param dat0 First track address
* @param dat1 Second track address
* @param dat2 Third track address
*/
void Combo_Play(uint8_t dat0, uint8_t dat1, uint8_t dat2) {
oneWireWrite(0xF3); // 0xF3 = Combo command
delay(20);
oneWireWrite(dat0);
delay(25);
oneWireWrite(dat1);
delay(25);
oneWireWrite(dat2);
delay(25);
}
/**
* @brief Stop any currently playing audio.
*/
void Stop_Play() {
oneWireWrite(0xFE); // 0xFE = Stop command
}
/**
* @brief Put the IC into low-power (sleep) mode.
*/
void Sleep_Mode() {
oneWireWrite(0xF0); // 0xF0 = Sleep command
}
/**
* @brief Wake the IC from low-power mode.
*/
void Wakeup_Mode() {
digitalWrite(DATA_PIN, LOW);
delay(40);
digitalWrite(DATA_PIN, HIGH);
delay(15);
}
Programming & Audio Upload
Reviews
There are no reviews yet.