Final
Post date: Aug 27, 2010 3:59:21 AM
So I've written the codes in Arduino and Processing for my drum glove to work. I made the glove out of 1/2 inch pipe insulator foam with a push button inserted into each of the 4 chunks of foam, one for each of the 4 fingers on one hand. I decided against making one for the thumb because it was too awkward to play it at the angle I needed to mount the push button at. I know using push buttons isn't the greatest way of building the glove, but it works the same as if they were pressure sensors. I haven't taught myself a song with it yet, but with enough time playing with it and it shouldn't be too long. Here are the codes:
Arduino:
int pushPin1 = 2; // denote which push pins are connected to which pins on the Arduino board
int pushPin2 = 3;
int pushPin3 = 4;
int pushPin4 = 5;
int val; // set up the variables
int val2;
int val3;
int val4;
void setup() {
Serial.begin(9600); // begin serial communication at 9600 bps
pinMode(pushPin1, INPUT); // set the pins on the Arduino board to input
pinMode(pushPin2, INPUT);
pinMode(pushPin3, INPUT);
pinMode(pushPin4, INPUT);
}
void loop() {
val = digitalRead(pushPin1); // read the value, store it in the variable
val2 = digitalRead(pushPin2);
val3 = digitalRead(pushPin3);
val4 = digitalRead(pushPin4);
if(val == HIGH) { // if the value is high,
Serial.print(val, DEC); // print the value to the serial port as a decimal (will be a 1 for high)
Serial.print("\t"); // and separate this value from the next with a tab
}
if(val == LOW) { // if the value is low,
Serial.print(val, DEC); // print the value to the serial port as a decimal (will be a 0 for low);
Serial.print("\t"); // and separate this value from the next with a tab
}
if(val2 == HIGH) {
Serial.print(val2, DEC);
Serial.print("\t");
}
if(val2 == LOW) {
Serial.print(val2, DEC);
Serial.print("\t");
}
if(val3 == HIGH) {
Serial.print(val3, DEC);
Serial.print("\t");
}
if(val3 == LOW) {
Serial.print(val3, DEC);
Serial.print("\t");
}
if(val4 == HIGH) {
Serial.println(val4, DEC);
}
if(val4 == LOW) {
Serial.println(val4, DEC);
}
delay(100); // delay 100 milliseconds before reading the values again
}
Processing:
import processing.serial.*; // import serial library
import ddf.minim.*; // import minim sound library
Serial myPort; // this next block of code just sets up the variables
AudioSample bass;
AudioSample snare;
AudioSample hiHat;
AudioSample cowbell;
Minim minim;
int fillBass;
int fillSnare;
int fillCymbalR;
int fillCymbalG;
int fillCowbellR;
int fillCowbellG;
void setup() {
size(400, 400); // sets the screen size
myPort = new Serial(this, Serial.list()[0], 9600); // tells the program to start paying attention to the serial port
myPort.bufferUntil('\n'); // store the data from the serial port until the value is reached
minim = new Minim(this); // begins the minim sound library
bass = minim.loadSample("Bass2.wav", 2048); // loads the audio samples
snare = minim.loadSample("Snare.wav", 2048);
hiHat = minim.loadSample("Hi_Hat.wav", 2048);
cowbell = minim.loadSample("Cowbell.wav", 2048);
background(0); // sets the background color
fillBass = 255; // these are used later to help distinguish when an element of the drum set is being played
fillSnare = 255;
fillCymbalR = 230;
fillCymbalG = 161;
fillCowbellR = 153;
fillCowbellG = 77;
}
void draw() {
stroke(0); // set the stroke color
fill(fillBass); // set the fill color. I used a variable so the color could change when a button is pressed
ellipse(width/2, 3*height/4, 150, 150); // draw the bass drum
fill(255);
rect(163, 3*height/8, 75, 30);
fill(fillSnare);
ellipse(width/2, 3*height/8, 75, 50); // draw the snare drum
fill(fillCymbalR, fillCymbalG, 0);
ellipse(width/4, height/4, 75, 25); // draw the cymbal
fill(fillCowbellR, fillCowbellG, 0);
stroke(fillCowbellR+10, fillCowbellG+10, 0); // I made the cowbell look 3-D just for kicks and giggles
rect(3*width/4, height/4, 30, 20); // draw the cowbell
quad(3*width/4, height/4, 320, 75, 340, 75, 330, 100);
quad(330, 100, 340, 75, 340, 85, 330, 120);
fill(0);
rect(305, 104, 20, 12);
}
void serialEvent(Serial myPort) { // when data is being received from the serial port, proceed with this function
String myString = myPort.readStringUntil('\n'); // read the data from the serial port until the value is reached
print (myString); // print the data being received
if (myString != null) { // if there is data
String myString1 = trim(myString); // cut out any whitespace
println(myString1); // print the data again to ensure it hasn't changed
int buttons[] = int(split(myString1, '\t')); // split the string of numbers at the tabs so they can be distinguished from each other
for (int buttonNum = 0; buttonNum < 4; buttonNum++) { // create 4 new variables (buttons[0-3]
println("Button " + buttonNum + ": " + buttons[buttonNum]); // print the new variables and their values
}
println(); // add a line after to separate old data from new incoming data. It just makes it easier on the eyes
if(buttons[0] == 0) { // if this button is pressed,
bass = minim.loadSample("Bass2.wav", 2048); // load this audio sample
bass.trigger(); // and play it
fillBass = 150; // change the fill color of the element of the drum set
delay(100); // delay so the color change is noticeable and the sound doesn't repeat too rapidly
fillBass = 255; // reset the fill color
}
if(buttons[1] == 0) {
snare = minim.loadSample("Snare.wav", 2048);
snare.trigger();
fillSnare = 150;
delay(100);
fillSnare = 255;
}
if(buttons[2] == 0) {
hiHat = minim.loadSample("Hi_Hat.wav", 2048);
hiHat.trigger();
fillCymbalR = 255; // I used 2 different variables here to denote the element's red and green fill amounts
fillCymbalG = 179;
delay(100);
fillCymbalR = 230;
fillCymbalG = 161;
}
if(buttons[3] == 0) {
cowbell = minim.loadSample("Cowbell.wav", 2048);
cowbell.trigger();
fillCowbellR = 179;
fillCowbellG = 89;
delay(100);
fillCowbellR = 153;
fillCowbellG = 77;
}
}
}
void stop() { // when the window is closed,
bass.close(); // close the audio samples
snare.close();
hiHat.close();
cowbell.close();
minim.stop(); // and stop minim
super.stop();
}
Here are some pics of the glove setup and a short video of the program working is attached.
So I realize this isn't exactly the same as the Megatap 3000, but it works in the same fashion. If I had time to order the force sensitive resistors online I would have, but these push buttons were the best alternative I could find.