14 March 2021

Project NIMES: Music Maker Box

 



As I was thing about how I would make this music box, I thought back to my time as a musician, where a lot of the time I had more fun playing the music rather then listening to it. That inspired me to make a music box that would be dependent on the users feedback and inputs to make sound. 

The concept would be to use some sort of input or two to play a few notes and edit the pitch or octave. With the potential of the potentiometer and the research for how the speaker of the CPE works, the mapping was very simple. The decision of WHAT to map was still there, since mapping all the notes from C0 to C8 would have the potentiometer be too sensitive to not changing. Thus I experimented with the mapping, trying to map roughly 3-4 octaves. 

Feedback would be straight forward for this, one of the buttons in the CPE would play the sound dependent of the potentiometer output. Meanwhile for the servo it would use another potentiometer to control its rotation, a means to have it act as a percussion to the music box. A question I would ask would be what are some idea to enhance feedback for this idea? Currently the only way you would know what note comes out is by pressing the button after adjusting the node. Would there be a better way to go about it?          





















//Edward Tavarez


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


Servo myServo; // servo reference

//pin references
const int analogInput = A1;
const int analogServoInput = A2;
const int analogServo = A3;

//public variables
int sensorValue = 0;
int servoAngle = 0;
int sensorOutput = 0;
int buttonRead = 0;
int servoPos = 0;

void setup() {
  // put your setup code here, to run once:
  
  //pinouts
  pinMode(analogInput, INPUT);
  pinMode(analogServoInput, INPUT);
  pinMode(CPLAY_LEFTBUTTON, INPUT_PULLDOWN);
  pinMode(CPLAY_RIGHTBUTTON, INPUT_PULLDOWN);
  
  //Init serial
  Serial.begin(9600);
  delay(1000);
  CircuitPlayground.begin();
  myServo.attach(analogServo);
}

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

}

void PlaySound()
{
    
  sensorValue = analogRead(analogInput); // read Potentiometer input
  int musicRange = map(sensorValue,5,1000,131,1047); //maps input
  buttonRead = digitalRead(CPLAY_LEFTBUTTON);

  //when button is pressed play not based on mapped music range  
  if(buttonRead == 1)
  {
    Serial.println(musicRange);
    CircuitPlayground.playTone(musicRange, 1000/8);
  }
}

void RunServo()
{
  //get servo roatation based on input rotation
  servoAngle = analogRead(analogServoInput);
  Serial.println(servoAngle); 
    myServo.write(servoAngle); // write servo angle 
    PlaySound();
    delay(15);
}



No comments:

Post a Comment

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