Saturday, February 26, 2011

Taiko Synth - Phase 3

We need to see the MIDI settings so they can be matched to the sounds from the Timidiy soft synth.

I used a serial LCD display from sparkfun:

http://www.sparkfun.com/products/9393

This is a great unit, and as a bonus, it can display katakana! Check the datasheet:

http://www.sparkfun.com/datasheets/LCD/st7066.pdf

Use the Arduino softserial library to talk to the display, because the main serial port is being used for MIDI. Lady Ada also has a softserial library, but I just used the one that came with Arduino.

Connect the display to power and to data on digital pin 3.

Explore the syth as follows.


C button: Toggle channel 0/9
Joy stick: up/down: change voice (instrument)
Joy Stick: left/right: change note
Z button: play note


I had considered using the nunchuck's built in accelerometer to trigger the note when playing "air drum" style, however that would encourage weaker hitting of the taiko, as you don't want to hold back when playing. Another option: mount the nunchuck and the stick and trigger on detecting the hits. I like this except I would need two nunchucks, and they both operate on the same i2c channel. This solution might need either two arduinos, figuring out to use the i2c library with two data channels, or changing the nunchuck channel.

Here's the code.



/*
* WiiMIDI --
* a06 display change in value as soon as joystick crosses threshold.
*
*
*
*/

#include
#include
#include
#include "nunchuck_funcs.h"

#define rxPin 2
#define txPin 3

int loop_cnt=0;
byte accx,accy,accz,zbut,cbut,joyx,joyy;
int ledPin = 13;
int note_on = 0;
int voice = 47;
int note = 60;
int channel = 9;

SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);

int debounce;

void setup()
{
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
midi_program_change(0, voice);

pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);

nunchuck_setpowerpins();
nunchuck_init(); // send the initilization handshake
printSettings();
midi_program_change(0, voice);
}

void loop()
{
delay(1);
nunchuck_get_data();

//accx = nunchuck_accelx(); // ranges from approx 70 - 182
//accy = nunchuck_accely(); // ranges from approx 65 - 173
//accz = nunchuck_accelz();
zbut = nunchuck_zbutton();
cbut = nunchuck_cbutton();
joyx = nunchuck_joyx(); //33L - 133C - 225R
joyy = nunchuck_joyy(); //25B - 128C - 224B

if(cbut == 1)
{
if(channel == 9)
{
channel=0;
//printMsg((char*)"nine");
//printSettings();
}
else
{
channel = 9;
//printMsg((char*)"zero");
//printSettings();
}
while(cbut == 1)
{
delay(100);
nunchuck_get_data();
cbut = nunchuck_cbutton();
//printMsg((char*)"release button");
}
printSettings();
}

if(joyy > 175)
{
voice++;
printSettings();
while(joyy > 150)
{
delay(100); //why does this delay prevent the app from getting hung up?
nunchuck_get_data();
joyy = nunchuck_joyy(); //25B - 128C - 224B
//printMsg((char*)"inc v");
}
midi_program_change(0, voice);
}

if(joyy < joyy =" nunchuck_joyy();"> 175)
{
note++;
printSettings();
while(joyx > 150)
{
delay(100); //why does this delay prevent the app from getting hung up?
nunchuck_get_data();
joyx = nunchuck_joyx(); //33L - 133C - 225R
//printMsg((char*)"inc n");
}
}

if(joyx < joyx =" nunchuck_joyx();" zbut ="="" zbut ="="" zbut =" nunchuck_zbutton();" joyx =" 125;" joyy =" 125;"> 100 )
// { // every 100 msecs get new data
// loop_cnt = 0;
// }
// loop_cnt++;
// delay(100);
}

void printSettings()
{
mySerial.print(0xFE, BYTE);
mySerial.print(0x01, BYTE);
mySerial.print("c:");
mySerial.print(channel);
mySerial.print(" v:");
mySerial.print(voice);
mySerial.print(" n:");
mySerial.print(note);
//delay(1000);
}

void printMsg(char* msg)
{
mySerial.print(0xFE, BYTE);
mySerial.print(0x01, BYTE);
mySerial.print(msg);
delay(1000);
}

No comments:

Post a Comment