Arduino Serial Control Tutorial

I’ve had a number of requests recently for help with using the WAV Trigger Serial Control Library for Arduino, so here’s a basic “how-to” using the example Uno sketch that’s now included in the library. For those of you unfamiliar with GitHub, fear not; Just use the “Download Zip” button on the library’s GitHub repo page (above link.)

 

Step 1: Install some Arduino libraries.

At a minimum, you’ll need to know how to install third party libraries into your Arduino development environment. There are plenty of tutorials available on that subject, so check ’em out and come back here when you’re up to speed. The example sketch requires 3 libraries be installed into your Arduino “libraries” folder.

Some Arduinos, such as the Uno, only have a single hardware serial port. I find it cumbersome to have to share with the USB connection when you need a serial port for your sketch. The AltSoftSerial library effectively creates another serial port out of normal digital pins. The specific pins it uses for RX and TX vary with the Arduino board type, and you can find out which ones by looking in the “known_boards.h” file in that library. All we need to know for now is that for the Uno, it makes Pin 9 be the TX pin.

Update: If you’d rather use a hardware serial port (UART) instead, the library now also supports Serial, Serial1, Serial2 or Serial3. The caveat is that you have to make one small edit in the wavTrigger.h file. See the library readme file for the details of how to do this.

Metro is a great interval timer class when you need to schedule events that you can’t use delay() for, such as blinking lights. The nice thing is that it doesn’t use any hardware timer resources. I use it a lot, and you should too.

 

Step 2: Prep your WAV Trigger.

I strongly advise that you install post headers or receptacles in any WAV Trigger connector that you’re planning to use. PCB connector pads are not meant for direct soldering and I’ve seen too many pads ripped off boards because people solder directly to them and don’t provide strain relief.

The example Arduino sketch is written to use a specific set of audio tracks. Download these tracks, unzip and copy them to the WAV Trigger’s microSD card. They already have the correct track names. You do not need an init file for this example unless you’re using the on-board amplifier and a speaker instead of the line out audio jack.

 

Step 3: Connect the WAV Trigger to the Uno.

The library currently only implements commands to the WAV Trigger, so you only need to connect 2 wires: GND, and the Uno TX pin to the WAV Trigger RX pin.

UnoHookup

 

Step 4: Power up and run the sketch.

Apply power to both boards and connect your USB cable to the Uno. If the libraries have been installed properly, you should be able to open the WTriggerUno sketch: File->Sketchbook->libraries->WavTrigger->wTriggerUno.

This example sketch demonstrates many of the library’s functions for starting, looping, fading, cross-fading, stopping tracks and groups of tracks and sample-rate (playback speed) control. It makes use of the sample tracks from Step 2 above, and probably won’t make much sense if you try to use your own sounds as is. You can of course, modify the example sketch to work with any sounds you wish.

The example sketch also assumes you have recent firmware in your WAV Trigger. Some of the features demonstrated by the sketch, such as pitch bending, have been added since the last SparkFun release firmware, so in order to get the full effect, you may need to update your WAV Trigger with the latest version from the download page.

 

Extra Credit: Powering the WAV Trigger from the Uno.

It’s possible to power the WAV Trigger from the Arduino 5V, although you probably should not do this if you’re planning to drive a speaker continuously at high-levels using the on-board amplifier, due to potentially high 5V current draw (even though I do.)

First you’ll need close the solder jumper on the WAV Trigger that connects the on-board 5V to the serial connector. The WAV Trigger doesn’t ship from SparkFun this way, because people might connect an FTDI Basic at the same time that they’re powering the WAV Trigger from the barrel connector. I always close this jumper because it allows me to power the WAV Trigger from the FTDI basic.

WTrig_Jumper001

Now just connect a 3rd wire from the Uno 5V pin to the WAV Trigger pin labeled “5Vin” next to the serial RX pin. Make sure not to power the WAV Trigger from the barrel connector at the same time!

 

 

Jamie

  • reply Mike Dodds ,

    Jamie,

    What would you recommend for a strategy for releveling gain on playing tracks on-the-fly?

    • reply jamie@robertsonics.com ,

      Use the trackFade() command, if I understand your question properly.

    • reply jérémy Morelle ,

      Hello,
      is there any chance you add the function to get the track name (or at least the track number)?
      Thanks for your module, it’s a great work.

      • reply f4ckturd ,

        hey if you want to use wav trigger with arduino mega 2560 r3 , what the “pin 9” on that one ?
        thatnks! great product!

        • reply djsoulmachine ,

          Hi Jamie!
          I would like to control the wav trigger with MIDI and an Arduino (the MIDI will be received by the Arduino and re-send to the Wav trigger by the Arduino).

          I assume that :
          – I need to modify the wavtrigger.h to set the serial output to 31250
          – I need to set the INITmaker to “MIDI”

          Could you please confirm ?
          Thanksa lot Jamie!
          Jérémie

          • reply jamie@robertsonics.com ,

            The WAV Trigger Arduino Serial Library supports the WAV Trigger serial protocol, which is not MIDI. Just changing the baud rate in the library does not make it MIDI. It’s a different protocol. If you want to transmit MIDI from the Arduino, I’d suggest using an existing Arduino MIDI library. And yes, you’ll need to set the WAV Trigger to MIDI mode using the init file.

            • reply djsoulmachine ,

              Yes, I forgot to mention that I do use a MIDI library to make the MIDI datas going through the Arduino to the WAV trigger.
              My only question was about the Baudrate since, correct me if I’m wrong, your wavtrigger.h set the serial output at 51700kbps. But maybe the init file overcome this parameter?

              • reply djsoulmachine ,

                Appart from the MIDI I’ll use the Arduino to control the SampleRate

                • reply jamie@robertsonics.com ,

                  Setting the serial port to MIDI mode in the init file will automatically set the baud rate to 31.25kbps. In MIDI mode, you’ll need to use MIDI Pitch Bend messages to control sample rate.

                  • djsoulmachine ,

                    OK, so the setSampleRate() function is no longer available in MIDI mode? 🙁

                    • jamie@robertsonics.com ,

                      It never was. I think you’re confusing MIDI with the WAV Trigger’s native serial protocol supported in the Arduino library. The WAV Trigger’s serial port can only be set for one or the other – not both at the same time. The default serial mode supports the native serial protocol messages described in the on-line user’s guide and is compatible with the Wav Trigger Arduino library. It includes a sample-rate offset command.

                      When the serial port is put into MIDI mode via the init file, the WAV Trigger only recognizes standard MIDI messages. MIDI has no “sample-rate offset” message, but it does have MIDI Pitch Bend, which effectively does the same thing.

                      It’s always been this way.

                  • reply djsoulmachine ,

                    Does this mean that I cannot go further than 5 semitones in MIDI mode ?
                    I actually need to reach 0.5x speed…
                    Thanks a lot Jamie, this will me my last question 🙂

                    • reply jamie@robertsonics.com ,

                      The latest firmware version, v1.18, supports a MIDI Pitch Bend range of +/- 7 semitones. If you need the full range, you have to use the serial protocol, not MIDI. I will point out here that if you’re already using an Arduino to read MIDI, using the WAV Trigger’s native serial protocol (and the Arduino library) gives you a lot more flexibility. Because you’re starting the tracks yourself, you have independent volume control of each track, and you can create any MIDI note to track mapping you want.

                      • djsoulmachine ,

                        Thanks a lot for all you answers Jamie!
                        My purpose is actually to build a musical instrument, this is why I use the Arduino MIDI library because it is really powerfull in terms of low latency and functionality. If I use the serial protocol, I’m not sure I am capable enought to write a sketch able to receive MIDI and trigger the tracks with the same efficiency… I studied a lot the wav trigger sketch you provided and I didn’t see a easy way (I mean easy for me !) way to do it…

                        Maybe I’ll have to forget this “Half Speed” feature for my project :'(
                        If you plan to extend the range of the MIDI pitch bend, please let me know!
                        Or even just a “Half Speed” trigger, I actually don’t need all the semitones between 🙂

                        Thanks again Jamie, you’re the best!

                • reply diandeRocker ,

                  Hello, i like the Wav-trigger board a lot, the Mellotron is so fantastic.
                  And this board is great, so many on this little thing, and send it different Midi channels
                  and it is multi-timbral, Great work, thanks.
                  My Question is about the samples put on the Micro-sd card, i put some on it converted and numbered
                  right and not all samples work, some do and some don’t, any clue for how this is happening,
                  I use a Kingston 8 gb card, and fill it with WinXP or Win7,
                  When i try to access the card sometimes the computer says it’s write protected.
                  So i try again after a reboot and then it’s accessable.
                  Thanks in advance, Dian from the Netherlands

                  • reply jamie@robertsonics.com ,

                    You must be sure that your samples are saved as 16-bit, stereo, 44.1kHz wav files with no meta-data stored in the file. Audacity, a free open-source audio editor, can be used to read and then re-save a .wav file in the correct format.

                  • reply Jeremie ,

                    Hi,
                    In your Github documentation it is written than the track number t can only be between 1 and 999, is it still true?

                    I actually didn’t see this statement before and I loaded my SD card with more than 1000 wav files and, surprisely, when I made some tests with the wTrig.playTrackPoly(int t) function, the files above 1000 are playing and the files below 1000 are not… That does not make sense, does it?

                    Thanks in advance!

                    • reply jamie@robertsonics.com ,

                      The latest version of the WAV Trigger firmware supports up to 2048 tracks and the library doesn’t limit the number sent. I’ll change github readme – thanks for pointing that out. Not sure why tracks under 1000 aren’t playing for you. Make sure you include the leading 0’s in the track filename, i.e. “0016_xxx.wav”. Try playing one of the low number tracks with a trigger input.

                    • reply Tom ,

                      I am trying to get the examples running and and getting the error ‘class AltSoftSerial’ has no member named ‘clear”. This same error (HardwareSerial rather than AltSoftSerial) shows up if I try to use the Hardware Serial port. What am I missing?

                      • reply jamie@robertsonics.com ,

                        I recently incorporated changes to add two-way serial communications done by hwestbrook – see the Jul 7 commit. Until I can have a look, I suggest using the Apr 26, 2015 commit which does not have this issue.

                        If you would please post this issue on the github site, perhaps he’ll have time to fix it before I will.

                        • reply Mark ,

                          Another user noted on github that commenting out the offending line in wavTrigger.cpp [line 51: WTSerial.clear(); ] fixed the problem. This appears to work for me as well, though I haven’t done much experimentation with the wavTrigger yet.

                      • reply AlexW ,

                        I followed the tutorial along with the example program (+ example wav files) on an Uno, but could not get the wav trigger playing any file through the arduino. Only by pressing the button on the wav trigger the first sound played successfully. Rx is wired to pin 9 and the LED at 13 is blinking as programmed in the example program. I currently do not have a device to update the firmware.
                        Any suggestions?

                        • reply jamie@robertsonics.com ,

                          Serial communication is notoriously difficult to troubleshoot without an oscilloscope to see where the problem is. It sounds like you have a wiring problem or even a hardware issue with your WAV Trigger or Uno.

                        • reply Darin ,

                          I’m using the WT alongside a SparkFun MIDI shield (on an Uno). The MIDI shield has a hard requirement of using pins 8 and 9 for soft serial. Is there any way to use another pin besides 9 with the WT? I looked through the library code but didn’t see anything obvious.

                          • reply jamie@robertsonics.com ,

                            If I understand your question correctly, AltSoftSerial requires the use of pin 9 for its TX on the Uno. This is a limitation of AltSoftSerial and the Uno, which has limited resources and only the 1 hardware serial port used for programming. If you need 2 serial ports (WAV Trigger plus MIDI) I’d recommend the Teensy, which has 3 hardware serial ports. I’ve used this to handle both MIDI and the WAV Trigger’s serial protocol.

                          • reply Russ ,

                            Hi Jamie, I’m new to the fascinating world of electronics and could use a little guidance in getting the WTriggerResponse working in my particular environment. I’m building a customized bird clock using the WAV Trigger and the Arduino Pro Mini. I’ve successfully compiled and uploaded the WTriggerResponse sketch to the Pro Mini (had to comment out line 51: WTSerial.clear(); in the wavTrigger.cpp to get it to compile) so I can test serial communication from the Arduino to the WAV Trigger.

                            I’m powering the Pro Mini from the WAV Trigger. To do this I’ve powered the WAV Trigger using the barrel jack (9vdc) and connected wires from the VIN and GND pins next to the barrel jack to the VCC and GND pins on the Pro Mini. For the serial communication I’ve connected the TXO pin on the Pro Mini to the RX pin on the WAV Trigger.

                            When I power up the WAV Trigger I see a red light flashing (every 2-3 seconds or so) and there’s a solid red light on the Pro Mini. I was thinking I could use the Arduino Serial Monitor (under the Tools menu) to provide input. When I enter ‘p’ and click “Send” nothing happens (I was expecting to see output on the Serial Monitor). I’ve tried sending ‘p’ and ‘s’ values using the various sending options (no line ending, newline, carriage return, both NL & CR) but that made no difference … any ideas?

                            • reply jamie@robertsonics.com ,

                              First, you should be aware that you are not actually “powering the Pro Mini from the WAV Trigger”. You’re simply tapping into the output of your 9V supply, which is powering both boards.

                              Second, if you don’t connect the WAV Trigger’s TX to the Pro Mini’s RX, then you won’t get responses in any event. And unless your Pro Mini code is echoing characters from the debug serial to/and from the WAV Trigger serial port, the serial monitor is in no way connected the WAV Trigger.

                              Third, I think you’re confusing the WAV Trigger’s serial protocol with the MP3 Trigger’s. They are completely different, and the WAV Trigger does not support typing ASCII commands from a terminal program.

                              I suggest you start by following the original “WTriggerUno” example in the library. Make sure you understand the code in the example sketch.

                              Unless you need responses from the WAV Trigger, you might also consider using the previous library commit. The recent addition, which introduced the compile problem was not done by me, and I just haven’t had a chance to clean this up.

                            • reply Russ ,

                              …meant to say when ‘p’ was entered I expected to hear sounds through the headphones and to see text output on the Serial Monitor when ‘s’ was entered.

                              • reply Russ ,

                                Thank you Jamie for your quick response, explanations, and guidance … I will try the WTriggerUno tutorial this afternoon and see how that goes.

                                • reply Russ ,

                                  Great news! I was finally able to get the wTriggerUNO sketch working. The problem I was having was connecting the RX pin on the WAV Trigger to the TXO (D1) pin on the Pro Mini. Once I connected the RX pin on the WAV Trigger to pin 9 (D9) on the Pro Mini everything worked. Thanks again for all your help!

                                  • reply george ,

                                    please , if you be so kind and help me please …

                                    i want to build a project similar to robert ‘s youtube demo
                                    something like a piano with 10 buttons connected to arduino also i want to include a potentiometer so i can change the pitch ..(i know that its a looooot simpler to just use the wav trigger alone ,, but it is very very important for my project to change the pitch at any given time … so the arduino have to stay)

                                    but i dont understand how to put the code together!!

                                    i have previously build exactly the same project but with a lower quality “”wav board”” and worked fine..
                                    but now its more complicated for me ..

                                    can anybody help please ..
                                    can you sent me the code ?? it wont be more than 30 lines…
                                    i also sent the same message at github .. may someone can answer there !!

                                    Thanks a lot
                                    George

                                    • reply Jamie ,

                                      The Tsunami Arduino Serial Control Library contains several example sketches that demonstrate, among other things, how to control the pitch.

                                    • reply george ,

                                      Thanks but I use the wav trigger not tsunami . And the example code is too complicated for me … I can understand how to trigger the sounds but I don’t know how to change the pitch with a potentiometer !!!

                                      • reply Jamie ,

                                        The same example is in the WAV Trigger Arduino Library, it demonstrates how to trigger tracks and change the pitch. The example is as simple as it can be.

                                        You’re asking for help with how to hook up a potentiometer to an Arduino, and write Arduino code to read ADC values. This is a question best asked in an Arduino forum.

                                      • reply Alcwyn ,

                                        Hi, Jamie, I have been using this shield for a project and it seems to be working quite well but every so often it stops playing full tracks and instead just plays one second. Is there any reason that you know of why it might be doing this? Any help would be greatly appreciated.

                                        • reply Jamie ,

                                          I’m not aware of any outstanding issue with the WAV Trigger that would explain this, so I’d need a lot more info to be of any help. Does it do this just once, or continuously until a power cycle? How to you fix it? I assume you are using Arduino serial control… what if you restart your Arduino without resetting the WAV Trigger? Can you post code? I’m afraid you’ll have to narrow things down a bit before I can help.

                                        • reply Alcwyn ,

                                          Hi Jamie, thanks for your quick reply and sorry for the initial vagueness. here is a link arduino sketch: https://codepaste.net/oami3q
                                          The board is being controlled by a Uno that is in turn being controlled by a yun. The uno is not freezing up as the lightwave functionality (used to turn plug sockets on and off) continues to function when the wav trigger has crashed. I am not changing the levels or anything like that. It really is just telling the board to play tracks. Sometimes it works for while and other times the one second playback happens quite quickly.

                                          Kind regards,
                                          Al

                                          • reply Jamie ,

                                            Once it happens, how do you fix it? Does it continue to do this until you cycle the power? When it stops playing prematurely, does the LED do anything? For example, if this is a power issue and the WAV Trigger is resetting, you’d see the LED blink 3 times when it stops playing. Are you using the on-board audio amplifier to drive a speaker?

                                            • reply Alcwyn ,

                                              Hi Jamie,
                                              Thanks again for your reply. I am using a standard 12v power supply and utilising the line out (no onboard amp). The board has to be powered down in order to work again. I have a few sounds that are shorter than one second, would this be an issue. After a while the board just starts playing 1 second of each wav file. It is quite intermittent. The project is a 1m diameter sphere with 202 toggle/LED switches. It’s looking amazing and everything is perfect apart from this issue 🙁

                                              • reply Jamie ,

                                                Well, this is certain not normal behavior nor is there any known outstanding issue that would cause this. If this were design or firmware issue, I would have heard about it long ago. Short files should not be a problem, unless they are only a couple of milliseconds long, and then they wouldn’t affect the longer files. Because it’s intermittent and seems to only happen after awhile, I’d suspect either heat or manufacturing defect, such as a bad solder joint. I’d suggest first trying a 9V supply, or better yet a 6V supply, and perhaps contacting SparkFun for a replacement. I’ve very occasionally seen bad solder joints on the microSD card socket…

                                          • reply Alcwyn ,

                                            • reply george ,

                                              please help

                                              • reply george ,

                                                hi Jamie

                                                I did the research about potentiometers as you advised me.

                                                but still I couldn’t figure out how to make it work.
                                                I need your help ..please..

                                                here is a simple code 1 button that plays a sound and 1 potentiometer that change the pitch..

                                                the button works fine but I have no response from the pot…

                                                what I did wrong? how to correct it .
                                                here is the code:
                                                #include
                                                #include // Arduino build environment requires this
                                                #include

                                                #define LED 13 // our LED

                                                wavTrigger wTrig; // Our WAV Trigger object

                                                Metro gLedMetro(500); // LED blink interval timer
                                                Metro gSeqMetro(6000); // Sequencer state machine interval timer

                                                byte gLedState = 0; // LED State
                                                int gSeqState = 0; // Main program sequencer state
                                                int gRateOffset = 0; // WAV Trigger sample-rate offset
                                                int sensorPin=A0;
                                                int sensorvalue=0;
                                                // constants won’t change. They’re used here to
                                                // set pin numbers:
                                                const int buttonPin = 2; // the number of the pushbutton pin
                                                const int ledPin = 13; // the number of the LED pin

                                                // Variables will change:
                                                int ledState = HIGH; // the current state of the output pin
                                                int buttonState; // the current reading from the input pin
                                                int lastButtonState = LOW; // the previous reading from the input pin

                                                // the following variables are unsigned long’s because the time, measured in miliseconds,
                                                // will quickly become a bigger number than can be stored in an int.
                                                unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
                                                unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers

                                                void setup() {
                                                Serial.begin(9600);
                                                pinMode(buttonPin, INPUT);
                                                pinMode(ledPin, OUTPUT);

                                                // set initial LED state
                                                digitalWrite(ledPin, ledState);
                                                wTrig.start();
                                                delay(10);

                                                // Send a stop-all command and reset the sample-rate offset, in case we have
                                                // reset while the WAV Trigger was already playing.
                                                wTrig.stopAllTracks();
                                                wTrig.samplerateOffset(0);

                                                }

                                                void loop() {
                                                // read the state of the switch into a local variable:
                                                sensorvalue =map(sensorPin,0,1023, -32767,+32767) ;
                                                int reading = digitalRead(buttonPin);

                                                // check to see if you just pressed the button
                                                // (i.e. the input went from LOW to HIGH), and you’ve waited
                                                // long enough since the last press to ignore any noise:

                                                // If the switch changed, due to noise or pressing:
                                                if (reading != lastButtonState) {
                                                // reset the debouncing timer
                                                lastDebounceTime = millis();
                                                }

                                                if ((millis() – lastDebounceTime) > debounceDelay) {
                                                // whatever the reading is at, it’s been there for longer
                                                // than the debounce delay, so take it as the actual current state:

                                                // if the button state has changed:
                                                if (reading != buttonState) {
                                                buttonState = reading;

                                                // only toggle the LED if the new button state is HIGH
                                                if (buttonState == HIGH) {
                                                wTrig.masterGain(-8); // Lower main volume

                                                wTrig.trackPlayPoly(6); // Play first note

                                                }
                                                }
                                                }

                                                // set the LED:
                                                digitalWrite(ledPin, ledState);
                                                wTrig.samplerateOffset(sensorvalue);
                                                // save the reading. Next time through the loop,
                                                // it’ll be the lastButtonState:
                                                lastButtonState = reading;
                                                }

                                                any ideas?

                                                if sent it 2 times please delete the previously

                                                • reply george ,

                                                  ok !!!!!
                                                  finally found the mistake !!
                                                  I forgot the analogRead(sensorPin) in map
                                                  I was wrote map(sensorPin,0,1023… inset of map(analogRead(sensorPin),0,1023,…

                                                  thax for your time!!

                                                  • reply Scott ,

                                                    Hi Jamie, the wavtrigger is awesome. I have used them in several applications. Thanks! In this case i need to adjust the volume for all tracks. I just need to know how you represent -70db in a signed int. I’m trying to setup 10 volume increments with this application. Thanks in advance. Cheers, Scotty.

                                                    • reply Jamie ,

                                                      Thanks for the kind words.

                                                      You don’t mention if you are using the Serial Protocol or the Arduino Library… You can use the Master Volume command to set the output level of all tracks. If you’re using the Arduino Library, you just pass a dB level as a signed integer in the range of -70 to +10. If you’re using your own serial code, then have a look at the Arduino Library source code to see how to turn a signed int into the actual command bytes.

                                                      Volume parameter is in dB, so 0 is no gain, +3dB is twice as loud, and -50dB is pretty much inaudible.

                                                      Hope this helps.

                                                    • reply Scott ,

                                                      Hi Jamie,
                                                      Thanks for the response. I’m still stuck on what is probably a very simple thing. I’m using the serial protocol for this project.
                                                      I have no problems assigning volumes above 0dB…It’s just when I want to go below to say..-10dB for example.
                                                      So for 0dB I’m sending, [$f0,$aa,$07,$05,$00,$00,$55] What would byte 5 & 6 be for -10dB? I think my problem is just understanding how to represent the signed int. Thanks again for your help. Cheers, Scott.

                                                      • reply Jamie ,

                                                        -10 decimal as a 16-bit signed integer hex value is 0xfff6, so byte 5 (LSB) is 0xf6 and byte 6 (MSB) is 0xff. You may want to read up on signed negative numbers in hex.

                                                      • reply Rob ,

                                                        Hi Jamie (and everyone else)
                                                        I’m using an Arduino Mega to control a WavTrigger in a pinball project I’m working on. I have one set of switches that go directly to the WT – triggers playing voice commands. I have an array of switches that pass through the Arduino to determine the ball locations. They then are connected through the serial connection to play music.

                                                        Here’s my question. Is there a command in the WavTrigger Arduino scetch that can play a random song (within a range of tracks say 10-20)?

                                                        Would this work?
                                                        wTrig.trackPlaySolo(int t)
                                                        wTrig.trackPlaySolo(10-20) or maybe wTrig.trackPlaySolo(10,20)

                                                        or would I need to use the random function in Arduino
                                                        randNumber = random(10, 20);
                                                        wTrig.trackPlaySolo(randNumber);

                                                        I can’t seem to find documentation anywhere.

                                                        Thanks

                                                        • reply Rob ,

                                                          So I played around with it more today and answered my own question
                                                          I just used the random function in arduino and it worked

                                                          int randNumber;

                                                          randNumber = random(10, 20);
                                                          wTrig.trackPlaySolo(randNumber);

                                                          The next problem I’m working on..

                                                          Let’s say 001 Track is playing
                                                          I’d like a trigger (002) to Pause the current track (001 Track) that’s playing. Have it set for “Level triggered” , so 002 starts playing. When the switch is released, 002 stops playing and the original track (001) resumes playing.

                                                          Is that something that can be programmed with the init file maker?
                                                          Or do I need to do it with hardware?

                                                          Thanks

                                                          • reply Jamie ,

                                                            While I’ve never tried this, you could use a double pole button or switch to connect two triggers to the same button. One trigger would be set to “level” and play track 002. The other trigger would be set to “level” and Pause track 001. Easy enough to try it out.

                                                          • reply Rob ,

                                                            Thanks for the response. I’m going to try a software solution first. I think this might work

                                                            const int sd7 = 8; //sd7 Which wired to Solenoid 7 Center Shield – temporary switch which will pause main music

                                                            void setup() {
                                                            //Input switches. Pullup to make HIGH
                                                            pinMode (sd7, INPUT_PULLUP); //sd7 center shield

                                                            //Turn on Serial Monitor
                                                            Serial.begin(9600);

                                                            //Allow WAV Trigger to power up
                                                            delay(100);

                                                            //WAV Trigger start up
                                                            wTrig.start();

                                                            //start playing music – Track 25
                                                            wTrig.trackPlaySolo(25);
                                                            }
                                                            void loop()
                                                            {
                                                            if (digitalRead(sd7)==LOW) {
                                                            wTrig.trackPause(25); //Pause Main Music
                                                            wTrig.trackPlaySolo(29); //Play temporary sound file

                                                            //When sd7 switch open, resume paused music (Main Music)
                                                            if (digitalRead(sd7)==HIGH {
                                                            wTrig.resumeALLInSync();
                                                            }

                                                            • reply Jamie ,

                                                              Ummm… I think you need to detect changes in the switch state and only send those commands when the state changes from HIGH to LOW and LOW to HIGH. Otherwise, you’ll be sending constant commands as fast as your loop is running.

                                                              • reply Rob ,

                                                                I’m back with a couple questions. Thanks for the help.
                                                                1. can you explain the fade function? I’m trying to get a track to fade out.
                                                                let’s say Track 25, over 2 seconds.
                                                                so how would I code that
                                                                wTrig.trackFade(25,-70,2000,?);

                                                                Question 2 is back to my original problem. How to Pause a track. I rewrote the code, but for some reason the Pause is not working. Basically when I run it, it will select a song from tracks 100-110. But when the Shield comes up, the two tracks play on top of each other. MainMusicTrack does not pause.

                                                                I have 2 switches. 1 is in the shooter lane that selects the MainMusicTrack (sw36)
                                                                The second is attached to a shield that comes up between the flippers (sd7)

                                                                int NCD = 25;

                                                                //Main Music Selection
                                                                if (digitalRead(sw36)==LOW) {
                                                                buttonstatesw36 = digitalRead(sw36);
                                                                if (buttonstatesw36 != lastbuttonstatesw36) {
                                                                MainMusicTrack = random(MusicStart,MusicEnd); //Music Tracks currently 100-110
                                                                wTrig.trackPlaySolo(MainMusicTrack);
                                                                lastbuttonstatesw36 = buttonstatesw36;
                                                                }
                                                                delay(20);
                                                                }
                                                                if (digitalRead(sw36)==HIGH) {
                                                                buttonstatesw36 = 1;
                                                                lastbuttonstatesw36 = 1;
                                                                }
                                                                //End Main Music Selection

                                                                // Not Coming Down Shield
                                                                if (digitalRead(sd7)==LOW) {
                                                                buttonstatesd7 = digitalRead(sd7);
                                                                if (buttonstatesd7 != lastbuttonstatesd7) {
                                                                wTrig.trackPause(MainMusicTrack);
                                                                wTrig.trackPlaySolo(NCD);
                                                                lastbuttonstatesd7 = buttonstatesd7;
                                                                delay(20);
                                                                }
                                                                }

                                                                // Resume any Paused Tracks and stop NCD if shield down == HIGH
                                                                //Stops Playing NCD, Resumes Main Music if Paused, Starts cued-up Multiball Music
                                                                if (digitalRead(sd7)==HIGH) {
                                                                wTrig.trackStop(NCD);
                                                                wTrig.resumeAllInSync();
                                                                buttonstatesd7 = 1;
                                                                lastbuttonstatesd7 = 1;
                                                                }
                                                                //End Stopping NCD section

                                                                • reply Rob ,

                                                                  I seem to be doing a good job answering my own questions
                                                                  I moved the Pause higher up in the if statement and it now works
                                                                  So it’s Pausing every Loop if sd7 ==LOW

                                                                  if (digitalRead(sd7)==LOW) {
                                                                  buttonstatesd7 = digitalRead(sd7);
                                                                  wTrig.trackPause(MainMusicTrack);
                                                                  if (buttonstatesd7 != lastbuttonstatesd7) {
                                                                  wTrig.trackPlaySolo(NCD);
                                                                  lastbuttonstatesd7 = buttonstatesd7;
                                                                  delay(20);

                                                            • reply Michalis ,

                                                              here is a plan .. but can it worked?

                                                              8 buttons hooked up with the wave tigger
                                                              1 arduino in serial protocol connected to wav trigger so it can sent sample rate commands to wave trigger
                                                              so my question is .. when i trigger a sound from the wave trigger can i sent the serial command from arduino so the pitch is changing or should i also have to trigger the sounds from the arduino with serial comands to get it work??

                                                              ps : the sample rate command it must be before the triggered sound or can also be done “live” when a sound in playing?

                                                              Jaime thank you for your time… and THANK you for your beautiful product !!

                                                              • reply Jamie ,

                                                                You can start sounds with trigger inputs and then control the pitch using serial commands. You can send the pitch command anytime, including while the sound is playing. The example sketch in the Arduino library demonstrates how to control pitch while the sound is playing.

                                                              Leave a comment