14 March 2021

NIME Scaffolding Music Box

 


For my NIME Music Box Scaffolding project, I decided to go with a well known and popular tune, crazy train. My conceptual model for my name was to have it to where you have the servo mimicking a drum beat in the same tempo that the crazy train tune was in. With that, I wanted to have the potentiometer control the pitch that the tune is played via the circuit playground express speaker to allow for variation in each individual note. My music box has four primary inputs, the right button starts the servo and initiates the acoustic drum beat while the left button disables said beat entirely, the middle switch plays the crazy train tune and the potentiometer determines the pitch of the tune played via middle switch. How I achieved the variation in pitch was I had the potentiometer values mapped 1:1 to add to the specific tones being played to change each of the individual notes congruently throughout the entire tune. Overall, I very much so enjoyed going about and taking part in this assignment as a whole and am excited to see how others were able to go around and creatively partake in said assignment!


//NIME Scaffolding
//Programmed by Andrew Freitas

#include <Servo.h>
#include <Adafruit_Circuit_Playground.h>
#include <Adafruit_CircuitPlayground.h>

//Variables
Servo myservo;
int servoState = 0;
int pitchAdjust = 1;

void setup(){
  //Starts CPE
  CircuitPlayground.begin(); 
  //Recognize servo from A3
  myservo.attach(A3); 
  Serial.begin(9600);
  delay(1000);
}

void loop() {

  //Toggle Drum Beat
  if (digitalRead(CPLAY_RIGHTBUTTON)){
    servoState = 1;
  } 

  //Deactivate Drum Beat
  if (digitalRead(CPLAY_LEFTBUTTON)){
    servoState = 0;
  }
                  
  //Drum Beat
  if (servoState == 1){
    myservo.write(180);
    delay(150);
    myservo.write(0);
    delay(75);
  }

    //Potentiometer control
    pitchAdjust = analogRead (A7);
    Serial.println (pitchAdjust);
    pitchAdjust = map(pitchAdjust, 1, 1024, 1, 255);
    Serial.println (pitchAdjust);
        
  //Play Song: Crazy Train
  if (digitalRead(CPLAY_SLIDESWITCHPIN)) {         
    //Default values for crazy train, adds pitchAdjust to alter Pitch
    CircuitPlayground.playTone(370 + pitchAdjust, 100); //F#4
    CircuitPlayground.playTone(370 + pitchAdjust, 100); //F#4
    CircuitPlayground.playTone(277 + pitchAdjust, 100); //C#4
    CircuitPlayground.playTone(370 + pitchAdjust, 100); //F#4
    CircuitPlayground.playTone(294 + pitchAdjust, 100); //D4
    CircuitPlayground.playTone(370 + pitchAdjust, 100); //F#4
    CircuitPlayground.playTone(277 + pitchAdjust, 100); //C#4
    CircuitPlayground.playTone(370 + pitchAdjust, 100); //F#4
    CircuitPlayground.playTone(494 + pitchAdjust, 100); //B4
    CircuitPlayground.playTone(440 + pitchAdjust, 100); //A4
    CircuitPlayground.playTone(415 + pitchAdjust, 100); //G#4
    CircuitPlayground.playTone(440 + pitchAdjust, 100); //A4
    CircuitPlayground.playTone(494 + pitchAdjust, 100); //B4
    CircuitPlayground.playTone(440 + pitchAdjust, 100); //A4
    CircuitPlayground.playTone(415 + pitchAdjust, 100); //G#4
    CircuitPlayground.playTone(330 + pitchAdjust, 100); //E4
  }
}





No comments:

Post a Comment

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