20 March 2022

NIME Team 7

 NIME Glass Music Box


    For our music box, we wanted to create a music box that could allow us to create multiple types of audio output that could also be modified, in order to create a somewhat soft and somber vibe from both the speaker tone (Married Life from Pixar's Up) and the subtle clinking of glass coming in contact withe metal. Furthermore, both of these functions would be modifiable by the potentiometer using one:one mapping, as it was intended to both increase or decrease the rotation of the servo motor, as well as modify which of the two tones would be played based on the potentiometer's position. As the potentiometer turned, the song would change from the first part to the second part and the glass would clink faster. Unfortunately, due to some sort of circuit or part error, the potentiometer wouldn't play nice with the servo motor and speaker for one reason or another, and only certain individual states could be obtained in isolation with each other. Technically functional in some ways, but not what our exact vision was. Although the most obvious improvement is in plain sight here (actually getting everything to work at the same time), what do you feel could have made this project easier for us to achieve our goal? Should we have only had the potentiometer modify one thing? Should we have used one song instead of two? etc.


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

//Specifications for Song 1 (first half of the potentiometer)
//Notes: A, B, C, D, E, F, G, A
//440, 493.88, 523.25, 587.33, 659.25, 698.46, 783.99, 880};
float notes[] = {440, 493.88, 523.25, 587.33, 659.25, 698.46, 783.99, 880};
float song[] = {349.23,440,349.23,329.63,349.23,440,329.63,293.66};
float lengths[] = {250, 250, 250, 575,250,250,250,375};
int numNotes = sizeof(song)/sizeof(float);

//Specifications for Song 2 (second half of the potentiometer
float notes2[] = {440, 493.88, 523.25, 587.33, 659.25, 698.46, 783.99, 880};
float song2[] = {293.66, 349.23, 293.66, 261.63, 293.66, 440, 392};
float lengths2[] = {250, 250, 250, 400, 250, 250, 400};
int numNotes2 = sizeof(song2)/sizeof(float);

Servo myServo;
int pos = 0; //position
int inc = 1; //increment
int timer = 0;
int pot = A4;
int switchpin=7 ;



void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
delay(1000);
CircuitPlayground.begin();
myServo.attach(10); //Pad A3, connect servo here
pinMode(13, OUTPUT); //D13, Small Red LED
pinMode(4, INPUT_PULLDOWN); //CP Button, D4
pinMode(5, INPUT_PULLDOWN); //CP Button, D5

}

void loop() {
  // put your main code here, to run repeatedly:
 

//speaker tone section
//plays songs for set frequencies and length
if(digitalRead(4)) {
for(int i=0; i<numNotes; i++) {
  Serial.println(notes[i]);
  CircuitPlayground.playTone(song[i],lengths[i]);
}
}
else if(digitalRead(5)) {
for(int j=0; j<numNotes2; j++) {
  Serial.println(notes2[j]);
  CircuitPlayground.playTone(song2[j],lengths2[j]);
  }
}

//servo code section
int pot = analogRead(pot);
if(digitalRead(switchpin)) {
  int rotation = map (pot,0,1023,0,180);
  myServo.write(rotation);
  //maps servo speed to potentiometer in order to increase or decrease its speed
}

else {if(millis() > timer + 15) {
if(pos==0) inc = 1;
if(pos==180) inc = -1;
myServo.write(pos);
pos += inc;
timer = millis();
//establishes a base rate for the servo
}
}
}

 



 

No comments:

Post a Comment

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