Hi,
I’m wondering how to replicate the functions offered in the InitMaker app using Arduino’s Serial protocol.
I’ve successfully begun controlling the WAV trigger with an Arduino using Serial by following the online guides. I’ve installed the 3 necessary libraries (Metro, AltSerial, and WAV-Trigger-Arduino-Serial) and gleaned from the basic example code how to get sounds to play. I’m using 4 sparkfun touch sensors (link below) outputting on/off data into the Arduino. I’m also powering the WAV trigger through the serial input from Arduino by soldering the 5v jumper.
Three of the sensors should activate one short audio clip each, without retriggering or looping, and one sensor should activate several random sounds, also without retriggering or looping. I had this all working well by using the init-maker app to generate a hex file for the SD card. Could I theoretically just load that same hex file onto the SD card and work with Arduino from there or would I need to write all my own custom Arduino code for controlling tracks in the same ways that InitMaker does? Not sure how exactly to write the code to get retriggering turned off, but I may be able to figure that out.
I’ve been referencing the WAV trigger Online User Guide’s “Serial Control Protocol” section and also the README note from the Github library page and can’t find the answers at this link: https://github.com/robertsonics/WAV-Tri … l-Library
These are the sensors I’m using: https://www.sparkfun.com/products/12041
And here’s the code I have so far:
// ****************************************************************************
// Sketch: WTriggerUno
// Date Created: 4/22/2015
//
// Comments: Demonstrates basic serial control of the WAV Trigger from an
// Arduino.
//
// Programmers: Jamie Robertson, info@robertsonics.com
// To use this sketch, you'll need to:
//
// 1) Download + install the AltSoftSerial library.
// 2) Download + install the Metro library.
// 3) Connect 2 wires from the UNO to the WAV Trigger's serial connector:
//
// Uno WAV Trigger
// === ===========
// GND <------> GND
// Pin9 <------> RX
//
// If you want to power the WAV Trigger from the Uno, then close the 5V
// solder jumper on the WAV Trigger and connect a 3rd wire:
//
// 5V <------> 5V
//
// http://robertsonics.com/2015/04/25/arduino-serial-control-tutorial/
#include <Metro.h>
#include <AltSoftSerial.h> // Arduino build environment requires this
#include <wavTrigger.h>
#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
const int touch2 = 2; // Input pins for touch state
const int touch3 = 3; // touch sensors are also pulled low to gnd with 10k resistors
const int touch4 = 4;
const int touch5 = 5;
int buttonState147 = 0; //initialize each button to LOW
int buttonState258 = 0;
int buttonState369 = 0;
int buttonStateR = 0;
// ****************************************************************************
void setup() {
Serial.begin(9600); // Serial monitor
pinMode(LED,OUTPUT); // Initialize the LED pin
digitalWrite(LED,gLedState);
// If Arduino is powering WAV Trigger, we should wait for the WAV
// Trigger to finish reset before trying to send commands.
delay(1000);
// WAV Trigger startup at 57600
wTrig.start();
delay(10);
// Send 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);
wTrig.masterGain(0);
pinMode(touch2, INPUT);
pinMode(touch3, INPUT);
pinMode(touch4, INPUT);
pinMode(touch5, INPUT);
}
void loop() {
buttonState147 = digitalRead(touch2);
buttonState258 = digitalRead(touch3);
buttonState369 = digitalRead(touch4);
buttonStateR = digitalRead(touch5);
// If a touch is detected, turn on LED
if (buttonState147 == HIGH) {
digitalWrite(LED, HIGH);
wTrig.trackPlayPoly(1);
wTrig.trackLoop(1, false); //this didn't help the retriggering issue either
delay(100); /*short delay to keep audio clips from distorting
Short term solution while searching for way to keep audio
from retriggerig*/
} else {
digitalWrite(LED, LOW);
wTrig.trackStop(1);
}
if (buttonState258 == HIGH) {
digitalWrite(LED, HIGH);
wTrig.trackPlayPoly(2);
wTrig.trackLoop(2, false);
delay(100);
} else {
digitalWrite(LED, LOW);
wTrig.trackStop(2);
}
if (buttonState369 == HIGH) {
digitalWrite(LED, HIGH);
wTrig.trackPlayPoly(3);
wTrig.trackLoop(3, false);
delay(100);
} else {
digitalWrite(LED, LOW);
wTrig.trackStop(3);
}
if (buttonStateR == HIGH) {
digitalWrite(LED, HIGH);
wTrig.trackPlaySolo(random(4,7)); //will likely need to rewrite this using 'int i'
delay(100);
} else {
digitalWrite(LED, LOW);
}
}