small update: code update to add routines to increase and decrease volume, loop through audio files or playlists, and stop audio.
/*
Very basic example, WT588D Audio Module in one-line serial mode, controlled by the Digistump Oak
It cycles continuously through 5 sound files, defined by the AudioSequenceID, referred to as an Equation in the VoiceChip software
Neither the RESET or BUSY pins are required for this example, though can of course be used
*/
#define WT588D_DATA 6
byte AudioSequenceID = 0;
byte volume = 7; //set volume level from 0 to 7
byte i;
void setup() {
pinMode(WT588D_DATA, OUTPUT);
setVolume(volume);
}
void loop() {
WT588DCommand(AudioSequenceID);
AudioSequenceID++;
if (AudioSequenceID == 5) AudioSequenceID = 0;
delay(1500); //pause between audio play commands
}
void WT588DCommand(byte WTbyte) {
digitalWrite(WT588D_DATA, 0); //pull DATA low to wake up chip, 2-10 msec
delay(5);
for( i = 0; i < 8; i++) { //read each bit of the AudioSequenceID, and write to data pin
if (bitRead(WTbyte, i)) {
digitalWrite(WT588D_DATA, 1); //then write to data pin
delayMicroseconds(400); //2:1 high/low indicates high
digitalWrite(WT588D_DATA, 0);
delayMicroseconds(200);
}
else {
digitalWrite(WT588D_DATA, 1);
delayMicroseconds(200); //and 1:2 high/low indicates low
digitalWrite(WT588D_DATA, 0);
delayMicroseconds(400);
}
}
digitalWrite(WT588D_DATA, 1);
}
void setVolume(byte b) { //takes a value of 0-7 for volume control
volume = b;
WT588DCommand(b+224);
}
void incVolume() {
if (!volume >= 7) WT588DCommand(++volume);
}
void decrVolume() {
if (!volume) WT588DCommand(--volume);
}
void loopAudio() {
WT588DCommand(242);
}
void stopAudio() {
WT588DCommand(254);
}