Dohan Yucht Cheong Saha (DYCS) L1 Blog Post

Group #21 Members

  • Shubhro Saha
  • David Dohan
  • Miles Yucht
  • Andrew Cheong

We built a quite advanced drumkit with the force-sensing resistor. By toggling the input mode on an input button, the user changes the drum instrument sample. Then, he/she taps a drumbeat into the FSR. The drumbeat is recorded into processing and other samples can be recorded by cycling through samples with the input button. At the end, the final mode allows the user to play back all the recordings in unison, using Processing and our computer speakers. We chose this project because all of us are musically inclined; Shubhro is a musician, both David and Miles are singers, and Andrew is a dancer! Altogether, making a drum machine is really fun and awesome. The end product turned out to be a great success! We had some technical challenges, but at the end we pulled through. In the final result, we like that the machine manages to overlay recordings from different sound samples. Among the things that didn’t work, Processing wouldn’t play all the sounds we wanted it to on the Arch Linux machines. Everything worked OK on Shubhro’s Mac, though. Also, delays in sound playback were a difficult annoyance.


In these schematics, we’ve drawn the wiring for our drum kit, strength tester, and morning room lighter, respectively.



In this storyboard, we see a user previously fed up with music product software celebrate the ease-of-use in our drumkit.

Video of System in Action

Parts Used

  • Arduino
  • Button sensor
  • Two 330-ohm resistors
  • Force-sensitive resistor
  • Potentiometer
  • Various wires


Assembly Instructions

  1. To a breadboard, attach a force-sensing resistor (FSR) in series with one of the 330-ohm resistors in the pull-down configuration. Also attach the potentiometer in series with the other resistor, also in the pull-down configuration.
  2. Connect the second pin of the potentiometer to pin A2 in the Arduino.
  3. Connect pin A0 on the Arduino in between the FSR and the 330-ohm resistor.
  4. Attach the button to pin 2, the voltage source and ground from the Arduino.


Source Code

import processing.serial.*;
import cc.arduino.*;
import ddf.minim.*;

/*Drumkit for Princeton COS436 - HCI Lab 1.  David Dohan*/

Arduino arduino;
Minim minim;


/*Pins*/
//Analog in
int drumFsr = 0;
int volumePot = 2;
//Digital in
int modeButton = 2;
//Digital out
int beeper = 3;

/*Beat information*/
int numTracks = 10; //Number of tracks
int cTrack = 0;
int trackSize = 10000; // Most possible ticks
int lastBeat = 0;      // Last current tick before looping
int[][] tracks = new int[numTracks][]; //All the tracks
AudioPlayer[] sounds = new AudioPlayer[numTracks]; //Sounds to play for each track
String[] names = {"kick", "tss", "cymbal"};

/*state*/
int numStates = 5; //0,1 record/hold
int state = 1; //0:play 1:hold 2-4:record drum types
int beat = 0;
int cutoff = 20;
double delayms = 1;
int lHit = 0;


void setup()
{
    println("Serial ports: ");
    println(Serial.list());
    arduino = new Arduino(this, Arduino.list()[6],57600);
    arduino.pinMode(drumFsr, Arduino.INPUT);
    arduino.pinMode(volumePot, Arduino.INPUT);
    arduino.pinMode(modeButton, Arduino.INPUT);
    clearTracks(); //Initialize tracks

    minim = new Minim(this);

    //Load sounds
    sounds[0] = minim.loadFile("drums/kick.mp3");
    sounds[1] = minim.loadFile("drums/snare.mp3");
    sounds[2] = minim.loadFile("drums/cymbal.mp3");
    sounds[2].setGain(-10);
}

void cleanTracks() {
    
  
  
}

void nextState() {
    beat = 0;
    state = (state + 1) % numStates;
    if (state == 1) { 
        lastBeat = 0;
        clearTracks();
    } else if (state == 0) {
      cleanTracks();
    } else {
       println(names[state-2]); 
    }
}

void clearTracks() {
    for (int i = 0; i  cutoff && lHit < cutoff) {
      tracks[cTrack][beat] = hit;
  }
    //println(hit);
      beat -= 1;
      play();
      beat += 1;
    if (state == 2) { lastBeat = max(beat,lastBeat); }
    lHit = hit;
}

void play() {
    //Cheap edge case avoidance...
    if (beat <= 0 || beat == trackSize - 1) { return; }
    for (int t = 0; t  0 && tracks[t][beat] > tracks[t][beat-1] &&
        //tracks[t][beat] > tracks[t][beat + 1]) {
        if (tracks[t][beat] > 0) {
            //print("Play");
            //println(t);
            sounds[t].play(0);
        }
    }
}

void draw()
{
    /*
     * Check button - mode change?
     * If play, then play current tick. Advance.  Read potentiometer to get tempo
     * If hold, do nothing
     * If record, then record fsr to current track/tick.  Play other tracks as
     *      well.
     */
    
    if (arduino.digitalRead(modeButton) == arduino.HIGH) {
        //Manage debounce
        while (arduino.digitalRead(modeButton) == arduino.HIGH) { print("") ; }
        nextState();
        print("Debounced: ");
        println(state);
    } else {
        
        switch (state) {
            case 0:
                play();
                break;
            case 1:
                hold();
                break;
            default:
                record();
                break;
        }
    }
    beat = (beat + 1) % trackSize;
    delay(arduino.analogRead(volumePot));
}