Ok, here's where I am now. I have the LED configured to turn on and pulse on input from a momentary switch, the clash LED is accepting inputs from the Aux button and the clash sensor. Now the audio...the bane of my existence...The problem I am having is that the sound comes out garbled and runs together in an unintelligible clipping. I know I must have the code wrong somewhere, could anyone offer me a suggestion? I am using a WT588D-U set in 3-Line Serial mode, the sound files are WAV set at 16-bit at 22000hz. Now the code:
int LEDpin = 9; // LED on pin 9
int switchPin = 3; // momentary switch on 3, other side connected to ground
int clashButton = 10;
int clashLed = 6;
int buttonState = 0;
int buttonPushCounter = 0;
int buttonState1 = 0;
int lastButtonState = 0;
int clashPin = 2;
int clashSense = 0;
const int groundpin = 18; // analog input pin 4 -- ground
const int powerpin = 19; // analog input pin 5 -- voltage
const int xpin = A3; // x-axis of the accelerometer
const int ypin = A2; // y-axis
const int zpin = A1; // z-axis (only on 3-axis models)
#define WT588D_RST 7 //Module pin "REST" or pin # 1
#define WT588D_CS 12 //Module pin "P02" or pin # 11
#define WT588D_SCL 11 //Module pin "P03" or pin # 10
#define WT588D_SDA 13 //Module pin "P01" or pin # 9
#define WT588D_BUSY 4 //Module pin "LED/BUSY" or pin # 15
byte file_count = 1;
void setup()
{
pinMode(LEDpin, OUTPUT);
pinMode(switchPin, INPUT);
pinMode(clashLed, OUTPUT);
pinMode(clashButton, INPUT);
pinMode(clashPin,INPUT);
digitalWrite(switchPin, HIGH);
digitalWrite(clashButton, HIGH);
digitalWrite(clashPin,HIGH);
// WT588D-U
pinMode(WT588D_RST, OUTPUT);
pinMode(WT588D_CS, OUTPUT);
pinMode(WT588D_SCL, OUTPUT);
pinMode(WT588D_SDA, OUTPUT);
pinMode(WT588D_BUSY, INPUT);
digitalWrite(WT588D_CS, HIGH);
digitalWrite(WT588D_RST, HIGH);
digitalWrite(WT588D_SCL, HIGH);
pinMode(groundpin, OUTPUT);
pinMode(powerpin, OUTPUT);
digitalWrite(groundpin, LOW);
digitalWrite(powerpin, HIGH);
// ADXL335
analogReference(DEFAULT);
pinMode(xpin, INPUT);
pinMode(ypin, INPUT);
pinMode(zpin, INPUT);
}
void WT588D_Send_Command(unsigned char addr) {
unsigned char i;
digitalWrite(WT588D_CS, LOW);
delay(5); //delay per device specifications
for( i = 0; i < 8; i++) {
digitalWrite(WT588D_SCL, LOW);
if(bitRead(addr, i))digitalWrite(WT588D_SDA, HIGH);
else digitalWrite(WT588D_SDA, LOW);
delay(2); //delay per device specifications
digitalWrite(WT588D_SCL, HIGH);
delay(2); //delay per device specifications
} //end for
digitalWrite(WT588D_CS, HIGH);
} //end WT588D_Send_Command
void loop(){
{
{
int x = analogRead(xpin);
//add a small delay between pin readings. I read that you should
//do this but haven't tested the importance
delay(1);
int y = analogRead(ypin);
//add a small delay between pin readings. I read that you should
//do this but haven't tested the importance
delay(1);
int z = analogRead(zpin);
//zero_G is the reading we expect from the sensor when it detects
//no acceleration. Subtract this value from the sensor reading to
//get a shifted sensor reading.
float zero_G = 512.0;
//scale is the number of units we expect the sensor reading to
//change when the acceleration along an axis changes by 1G.
//Divide the shifted sensor reading by scale to get acceleration in Gs.
float scale = 102.3;
{
for (int fadeValue = 0; fadeValue <= 255; fadeValue +=5){
buttonState = digitalRead(switchPin);
buttonState1 = digitalRead(clashButton);
clashSense = digitalRead(clashPin);
if(buttonState !=lastButtonState){
if(buttonState == HIGH){
buttonPushCounter++;
}delay(50);
}
lastButtonState = buttonState;
if (buttonPushCounter %2 == 0){
analogWrite(LEDpin, fadeValue);
delay(50);
WT588D_Send_Command(0x01);
}else{
digitalWrite(LEDpin,LOW);}
if (buttonState1 == HIGH){
digitalWrite(clashLed, LOW);
} else {
digitalWrite(clashLed,HIGH);
}
}
if (clashSense == HIGH){
digitalWrite(clashLed,LOW);
} else {
digitalWrite(clashLed,HIGH);
} } } } }