14 March 2021

NIME - Basic Music Box


The concept for this music box is simple; to ensure I understand the new materials. It features all the core requirements for this project: a servo, a potentiometer, and at least two more inputs from the circuit playground express (CPE). I repurposed an old box from my house and cut out mounts for my essential parts. The CPE is held up by a smaller box that is also securing the breadboard under it. 

To create music, the user has a choice between digital and acoustic audio. There are two buttons for different types of sound. The digital audio plays a repetitive note. For the acoustic sound, there is a servo that repeatedly oscillates between two points. Depending on which sound type is active, the potentiometer can be used to adjust either the speed or tempo. The switch at the bottom can be used to toggle the sounds to loop. Mapping for the buttons is 1:1; one function per button, while the potentiometer has two functions. Without the written labels, there are various signifiers that this box has a function. The hole cut out to give access to the CPE serves as a signifier, since it gives easy access to both the speaker and the buttons. The potentiometer resembles a screw that can be twisted, while the servo looks almost like a little fan. As a result of these signifiers, the user knows what can be interacted with, and be aware of the different audio and visual feedback they will encounter. Everything that is visible does something or directly influences something else. 

For my peers: What could I have done to give the user more freedom to create more unique compositions and sounds?


/Libraries

#include <Servo.h>

#include <Adafruit_CircuitPlayground.h>

#include <Adafruit_Circuit_Playground.h>


//Code by Paulina Weintraub 2021


Servo myServo;


//Variables

int aCurrent = 0;

int aPrevious = 0;

int bCurrent = 0;

int bPrevious = 0;

int servoActive = 0;

int musicActive = 0;

int pitch = 1;

int tempo = 1;



void setup() {

  // put your setup code here, to run once:

  

  pinMode(CPLAY_LEFTBUTTON, INPUT_PULLDOWN); //Button A

  pinMode(CPLAY_RIGHTBUTTON, INPUT_PULLDOWN); //Button B

  pinMode(CPLAY_SLIDESWITCHPIN, INPUT_PULLDOWN); //Switch

  

  Serial.begin(9600);

  delay(1000);

  CircuitPlayground.begin();

  myServo.attach(A3);

}


void loop() {

  // put your main code here, to run repeatedly:


  //Loop beat

  bCurrent = digitalRead(CPLAY_RIGHTBUTTON);

  if(bCurrent == 1 && bPrevious == 0) {

    servoActive = 1;

  }

  if(servoActive == 1) {

    myServo.write(180);

    delay(tempo);

    myServo.write(0);

    delay(tempo);

  }


  //Potentiometer input and mapping

  //Pitch of note played

  pitch = analogRead(A2);

  pitch = map(pitch, 1, 1024, 1, 255);


  //Potentiometer input and mapping

  //Speed of servo

  tempo = analogRead(A2);

  tempo = map(tempo, 1, 1024, 1, 255);


  //Loop note

  //I decided not to use a song so that the user could make their own

    aCurrent = digitalRead(CPLAY_LEFTBUTTON);

    if(aCurrent == 1 && aPrevious == 0) {

       musicActive = 1;

    }

    if(musicActive == 1) {

      CircuitPlayground.playTone(440 + pitch, 100);

    }


    //When switch is active, looping is disabled

    if(digitalRead(CPLAY_SLIDESWITCHPIN)){

      servoActive = 0;

      musicActive = 0;

      CircuitPlayground.playTone(0, false);

      myServo.write(0);

      aPrevious = aCurrent;

      bPrevious = bCurrent;

    }

}




No comments:

Post a Comment

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