Im having issues with controlling the playback of sounds on the WT588D. Is there a code solution that would allow a sound to play and keep playing as long as a button was HIGH but stopped that sound as soon as the button went LOW? (or vise versa). I guess what i really need to know is how to trigger a sound from outside the main loop.
currently my AUX button (the one for the 'lockup') constantly restarts the sound over and over.
im running the WT in one-line serial mode. Do i need to have the WTs BUSY pin wired to make that work?
here is the code im using for the button.
const int WT588D_SDA = 9; //Module pin "P03" or pin # 10
const int AUX_BUTTON = 1;
const int BLADE_LED_AUX = 5; // led for flashes
int aux = 0; // variable for reading the pushbutton status
void setup() {
Serial.begin(9600);
// initialize the LED pin as an output:
pinMode(BLADE_LED_AUX, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(AUX_BUTTON, INPUT_PULLUP);
pinMode(WT588D_SDA, OUTPUT);
digitalWrite(WT588D_SDA, HIGH);
}
void loop() {
// read the state of the pushbutton value:
aux = digitalRead(AUX_BUTTON);
// check if the pushbutton is pressed.
// if it is, the state of the button is LOW:
if (aux == LOW) {
// turn LED on:
digitalWrite(BLADE_LED_AUX, HIGH);
WT588D_SendAudio (0x07);
Serial.println("LED_ON");
} else {
// turn LED off:
digitalWrite(BLADE_LED_AUX, LOW);
Serial.println ("LED_OFF");
}
}
void WT588D_SendAudio(byte addr){
digitalWrite(WT588D_SDA, LOW);
delay(5);
for(int i = 0; i < 8; i++) {
digitalWrite(WT588D_SDA, HIGH);
if bitRead(addr,i) {
delayMicroseconds(600);
digitalWrite(WT588D_SDA, LOW);
delayMicroseconds(200);
}
else {
delayMicroseconds(200);
digitalWrite(WT588D_SDA, LOW);
delayMicroseconds(600);
}
}
digitalWrite(WT588D_SDA, HIGH);
delay(10);
}
Anybody have suggestions?
auxbuttontest.ino.ino (1.39 KB)