20 March 2022

Project: NIME, Group 20, Drum Machine with Synthesizer Touch Pads



Video Demo


NIME Group 20 Christopher Crawford & Marcus Napoleoni

For our project we created an instrument similar to a keyboard but with a percussive extension and the ability to shift the pitch of the notes higher or lower. Our instrument has three notes mapped to A5-A7 on the CPE with alligator clips that extend through the top of the box with tinfoil “keycaps” that allow the notes to be played. A fourth key acts as an on-off switch for the servo on A2, which swings the “drum stick” and creates a rhythmic tapping on whatever you put in its path. The user could experiment with different objects to create unique sounds with the drum stick. Finally, we added a potentiometer on A1 which changes the pitch of the notes that the keys play. The highest frequency key by default is around 120htz and the max for the CPE is 440, so we mapped the potentiometers input between 0 and 300 and then added its mapped value to the frequency of each key so that the highest note at max is just under 440.

We wanted our instrument to have a large range of notes so that it would be capable of playing a large variety of songs and I believe we succeeded, especially since you can change the pitch of the notes while playing notes at the same time. There is some room for improvement, there could be more keys or speed settings for the drum stick, but my question to you is, how would you improve our code or the design layout of our instrument?

Project Code:

        #include <Servo.h>
        #include <Adafruit_CircuitPlayground.h>
        #include <Adafruit_Circuit_Playground.h>
        
        Servo myServo;
        int pos = 0;
        int inc = 90;
        int servoTimer = 0;
        
        int thresh = 400;
        int touchTimer = 0;
        int debounce = 160;
        
        void setup() {
          CircuitPlayground.begin();
          Serial.begin(9600);
          delay(1000);
          myServo.attach(10);  //A3
        }
        
        void loop() {
        
          if(millis() > servoTimer + 300) {                             //if at least 300 milliseconds have passed
            if(CircuitPlayground.readCap(A2) >= thresh) {     //and A2 is being touched
              if(pos == 0) inc = 90;                                        //bounce between 0 and 90 degrees
              if(pos == 90) inc = -90;
              myServo.write(pos);
              pos += inc;
              servoTimer = millis();
            }
          }
        
          if(millis() > touchTimer + debounce) {                  //if it has been at least "debounce" milliseconds
        
            int sensor = analogRead(A1);                               //read the state of the potentiometer
        
            int pitchShift = map(sensor, 0, 1023, 0, 300);      //map potentiometer value between 0 and 300
            
                   //    Serial.print(sensor);
                   //    Serial.print("\t");
                   //    Serial.println(pitchShift);
        
            if(CircuitPlayground.readCap(A4) >= thresh) { 
                         
                  //these if statements check if  A4-A7 are being touched

              CircuitPlayground.playTone(87.31 + pitchShift, 100, false);           

                 //if they are, play a note +  the value of the potentiometer to change pitch
            }
        
            if(CircuitPlayground.readCap(A5) >= thresh) {
              CircuitPlayground.playTone(98 + pitchShift, 100, false);
            }
        
            if(CircuitPlayground.readCap(A6) >= thresh) {
              CircuitPlayground.playTone(110 + pitchShift, 100, false);
            }
        
            if(CircuitPlayground.readCap(A7) >= thresh) {
              CircuitPlayground.playTone(123.47 + pitchShift, 100, false);
            }
        
            touchTimer = millis();
          }
        
        }

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.