14 March 2021

Branch_Nime_MusicBox

 


 

    In concept this design is a music box, something that the user opens up or otherwise interacts with and thus music will play. The inputs are ambient light, which outputs to everything, it is the base to get the box working and without it the box will not function. Then there is the knob, which controls the lights in the enclosure, and how bright they are. Finally there is touch, which will cause the song to start playing. The obvious signifies are the LED coming on when the box is opened, which tells the users the device is on, and the bone waving when exposed to light which tells the user it is ready to play its song when interacted with. I kept the box very simple, and given more time, would have sough to add more lights and waving bones along with a cleaner look. The general idea behind the box is a surprise, most music boxes have moving parts, but only ask for minimal interaction, the user has to go in and press the button, expecting only a bone related song to play. I chose Megalovania due to its popularity online, and I though it would give anyone a good surprise if they stumbled across this box and interacted with only to have boss music to being playing. Can you think of any other songs that would be very surprising or funny for a music box to start playing? 


 

 
  //Libraries
#include <Adafruit_CircuitPlayground.h>
#include <Adafruit_Circuit_Playground.h>
#include <Servo.h>
//needed libraries


Servo myservo;  // create servo object to control a servo

int pos = 0;
int inc = 1;
int timer = 0;
//control servo with timer so the delay does not interrupt the code too much



const int analogInPin = A1;  // analog pin used to connect the potentiometer
const int analogOutPin = 10; // Analog output pin that the LED is attached to
int sensorValue = 0;        // value read from the pot
int outputValue = 0;        // value output to the PWM (analog out)







void setup() {

  Serial.begin(9600);
  //serial monitor to monitor birghtness for bug testing
  delay(1000);
  CircuitPlayground.begin();
  myservo.attach(9);
  //attach servro to pin out 9
  pinMode(CPLAY_RIGHTBUTTON, INPUT_PULLDOWN);//Button B
  //activate right button
}

void loop() {
  int light = analogRead(A8);
  int bright = map(light, 0, 1023, 0, 255);
  //read the value of light around and map it for use
  Serial.println(light);
  Serial.print("\t");
  Serial.print(bright);
  Serial.print("\t");
  //serial monitor for bug testing
  //if the music box is open, begin the waving servo bone
  if (bright > 3) {
    sensorValue = analogRead(analogInPin);
    // map it to the range of the analog out:
    outputValue = map(sensorValue, 0, 1023, 0, 255);
    // change the analog out value:
    analogWrite(analogOutPin, outputValue);



    if (millis() > timer + 15) {
      if (pos == 0) inc = 1;
      if (pos == 180) inc = -1;
      myservo.write(pos);
      pos += inc;
      timer = millis();

      //servo code that does not use delay
    }




    if (digitalRead(CPLAY_RIGHTBUTTON)) {
      //if box is open in bright, and button is presssed, commence bad time
      CircuitPlayground.playTone(294, 90);
      CircuitPlayground.playTone(294, 90);
      CircuitPlayground.playTone(587, 90);
      delay(100);
      CircuitPlayground.playTone(440, 90);
      delay(100);
      CircuitPlayground.playTone(415, 90);
      CircuitPlayground.playTone(392, 90);
      CircuitPlayground.playTone(349, 140);
      CircuitPlayground.playTone(294, 90);
      CircuitPlayground.playTone(349, 90);
      CircuitPlayground.playTone(392, 90);

      CircuitPlayground.playTone(277, 90);
      CircuitPlayground.playTone(277, 90);
      CircuitPlayground.playTone(587, 90);
      delay(90);
      CircuitPlayground.playTone(440, 90);
      delay(90);
      CircuitPlayground.playTone(415, 90);
      CircuitPlayground.playTone(392, 90);
      CircuitPlayground.playTone(349, 140);
      CircuitPlayground.playTone(294, 90);
      CircuitPlayground.playTone(349, 90);
      CircuitPlayground.playTone(392, 90);

      CircuitPlayground.playTone(262, 90);
      CircuitPlayground.playTone(262, 90);
      CircuitPlayground.playTone(587, 90);
      delay(90);
      CircuitPlayground.playTone(440, 140);
      delay(90);
      CircuitPlayground.playTone(415, 90);
      CircuitPlayground.playTone(392, 90);
      CircuitPlayground.playTone(349, 140);
      CircuitPlayground.playTone(294, 90);
      CircuitPlayground.playTone(349, 90);
      CircuitPlayground.playTone(392, 90);

      CircuitPlayground.playTone(247, 90);
      CircuitPlayground.playTone(247, 90);
      CircuitPlayground.playTone(587, 90);
      delay(90);
      CircuitPlayground.playTone(440, 140);
      CircuitPlayground.playTone(415, 90);
      delay(90);
      CircuitPlayground.playTone(392, 90);
      CircuitPlayground.playTone(349, 140);
      CircuitPlayground.playTone(294, 90);
      CircuitPlayground.playTone(349, 90);
      CircuitPlayground.playTone(392, 90);
    }

  }
}




No comments:

Post a Comment

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