Wav Trigger and Potentiometer

Hi there, I’m trying to get Wav Trigger tracks to play when a potentiometer is between certain values and a button is pressed (via Arduino Uno). I can get LEDs to light with this action but no tracks play. It feels like I’ve tried everything so maybe it’s some kind of response time issue with the Wav Trigger…? Any ideas…? Thanks!

Here’s my code:

#include “AltSoftSerial.h”

#include “wavTrigger.h”

wavTrigger wTrig;

const int led = 13;

const int button = 2;

int buttonState = 0;

// the setup routine runs once when you press reset:

void setup() {

// initialize serial communication at 9600 bits per second:

Serial.begin(57600);

pinMode (led, OUTPUT);

pinMode (button, INPUT);

}

// the loop routine runs over and over again forever:

void loop() {

buttonState = digitalRead(button);

// read the input on analog pin 0:

int sensorValue = analogRead(A0);

// print out the value you read:

Serial.println(sensorValue);

delay(50); // delay in between reads for stability

if ((sensorValue > 0) && (sensorValue < 201)){

digitalWrite (led, LOW);

}

if ((sensorValue > 200) && (sensorValue < 301) && (buttonState == HIGH)){

digitalWrite (led, HIGH);

wTrig.trackPlaySolo(1);

}

if

((sensorValue > 200) && (sensorValue < 301) && (buttonState == LOW)){

digitalWrite (led, LOW);

}

if ((sensorValue > 300) && (sensorValue < 501)){

digitalWrite (led, LOW);

}

if ((sensorValue > 500) && (sensorValue < 601) && (buttonState == HIGH)){

digitalWrite (led, HIGH);

wTrig.trackPlaySolo(2);

}

if ((sensorValue > 500) && (sensorValue < 601) && (buttonState == LOW)){

digitalWrite (led, LOW);

}

if ((sensorValue > 600) && (sensorValue < 701)){

digitalWrite (led, LOW);

}

if ((sensorValue > 700) && (sensorValue < 800) && (buttonState == HIGH)){

digitalWrite (led, HIGH);

wTrig.trackPlaySolo(3);

}

if ((sensorValue > 700) && (sensorValue < 800) && (buttonState == LOW)){

digitalWrite (led, LOW);

}

if (sensorValue > 800) {

digitalWrite (led, LOW);

}

}

Hi Jay.

Are you sure your code is actually sending serial commands? What pin are you using as TX on the Arduino?

Also, in the future, please insert code using the code display tag. The button for this tag looks like </> in the button bar above.

That will make your code look like the code below and is much easier to read that way.

#include "AltSoftSerial.h"
#include "wavTrigger.h"

wavTrigger wTrig;
const int led = 13;
const int button = 2;

int buttonState = 0;




// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(57600);
pinMode (led, OUTPUT);
pinMode (button, INPUT);

}

// the loop routine runs over and over again forever:
void loop() {


buttonState = digitalRead(button);


// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);

delay(50); // delay in between reads for stability

if ((sensorValue > 0) && (sensorValue < 201)){
digitalWrite (led, LOW);
}

if ((sensorValue > 200) && (sensorValue < 301) && (buttonState == HIGH)){
digitalWrite (led, HIGH);
wTrig.trackPlaySolo(1);
}

if
((sensorValue > 200) && (sensorValue < 301) && (buttonState == LOW)){
digitalWrite (led, LOW);
}

if ((sensorValue > 300) && (sensorValue < 501)){
digitalWrite (led, LOW);
}

if ((sensorValue > 500) && (sensorValue < 601) && (buttonState == HIGH)){
digitalWrite (led, HIGH);
wTrig.trackPlaySolo(2);
}

if ((sensorValue > 500) && (sensorValue < 601) && (buttonState == LOW)){
digitalWrite (led, LOW);
}



if ((sensorValue > 600) && (sensorValue < 701)){
digitalWrite (led, LOW);
}

if ((sensorValue > 700) && (sensorValue < 800) && (buttonState == HIGH)){
digitalWrite (led, HIGH);
wTrig.trackPlaySolo(3);
}
if ((sensorValue > 700) && (sensorValue < 800) && (buttonState == LOW)){
digitalWrite (led, LOW);
}




if (sensorValue > 800) {
digitalWrite (led, LOW);
}

}

Hi Chris, thanks for your help!

Ah, apologies I’ll use the code tag next time.

I’m actually using pin 9 as TX through the AltSoftSerial.h library. This works fine if I just have a button to play tracks via Arduino. (I can’t remember why we have to use AltSoftSerial.h with a Wav Trigger but I’m assuming it’s necessary). Could the problem be that I’m actually using the physical serial bus/window to monitor the output of the potentiometer and therefore confusing things? I thought I could use both physical and software serials at the same time though?

Ah, apologies I’ll use the code tag next time.

No worries! :-)

I’m actually using pin 9 as TX through the AltSoftSerial.h library. This works fine if I just have a button to play tracks via Arduino. (I can’t remember why we have to use AltSoftSerial.h with a Wav Trigger but I’m assuming it’s necessary).

It looks like pin 9 is what’s coded into the library somewhere and that is where data is being sent, but I didn’t dig through to see where it’s assigned. AltSoftSerial is what the library is built on but I’m sure you could modify it to use SoftwareSerial if you wanted too. The library does have provisions for using the free hardware UARTs on a mega or other Arduino board that has multiple hardware UARTs available.

Could the problem be that I’m actually using the physical serial bus/window to monitor the output of the potentiometer and therefore confusing things? I thought I could use both physical and software serials at the same time though?

That shouldn’t be a problem since you’re not monitoring the altsoftserial port. Looking at your code, I see you’re missing a wTrig.start(); in void setup(). Without that, your sketch isn’t going to send any data to the WAV Trigger. Add that in and I think you might make some progress.

Wow, that’s a little embarrassing… Tight deadline and lack of sleep! Thanks for your very gracious pointer and info on SoftwareSerial.

“I can’t remember why we have to use AltSoftSerial.h with a Wav Trigger but I’m assuming it’s necessary”

It’s not necessary - you can use the WAV Trigger Library with hardware serial ports - you just need to change a define in the library header file. It’s documented in that file.

It just defaults to AltSoftSerial due to the UNO only having one hardware serial port which has to be shared with the programming interface.

Great, thanks pointing that out.