15 March 2021

 

Project: NIME







For this project, I was inspired by the movie, The Little Prince and thought of an idea to implement some of the key features to this music box/ instrument for the overall theme for this project. 

I wanted to have a centerpiece, much like a traditional music box, so I created the rose from the film and attached it to the servo and have it spin back and forth. I also attached a male connection wire to the servo in order to create audio from the metal tips scratching on the cardboard box as it spins.  


I wanted the user to control the pitch coming from the CPE, so I attached the potentiometer to the LED in order for the user to dim and raise the brightness. In turn, the light sensor detects the brightness and changes the pitch accordingly. The brighter the light, the higher the pitch and vice versa. This is activated when the switch on the CPE is turned on. To achieve this I used the map function for the light and audio values.

I also programmed the right button to play the theme song from The Little Prince and it turns off once the melody is completed.


Question: I would like feedback on my code. Am I missing anything or is there any feedback in regards to that.



CODE:

//NIME:music box/instrument code by Nadia Al-Ghamdi

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

    Servo myServo; //Controls servo

//variables
    int pos = 0;
    int inc = 1;
    int timer = 0;


void setup(){
   Serial.begin(9600);
   delay(1000);
   CircuitPlayground.begin();   
   myServo.attach(10); //A3
   pinMode(13, OUTPUT);
   pinMode(4,INPUT_PULLDOWN);  
   }
 
void loop(){
 
   if(millis() > timer + 15){
   if(pos == 0) inc = 1;
   if(pos == 180) inc = -1;
     myServo.write(pos);
     pos += inc;
     timer = millis();
   }
   digitalWrite(13,digitalRead(4));

  //adjust sound pitch depending on light brightness
   uint16_t value, sound;
   if(CircuitPlayground.slideSwitch()) {      //   switch on
     value = CircuitPlayground.lightSensor(); //   light sensor
     sound = map(value, 5, 100, 500, 5000);  //    light and audio values
     CircuitPlayground.playTone(sound, 250);  
   }

//Theme song for The Little Prince if right button is pressed
   if (CircuitPlayground.rightButton()) {
  CircuitPlayground.playTone(290, 200);
  CircuitPlayground.playTone(292, 200);
  CircuitPlayground.playTone(290, 200);
  CircuitPlayground.playTone(292, 200);
  CircuitPlayground.playTone(290, 200);
  CircuitPlayground.playTone(292, 200);
  CircuitPlayground.playTone(330, 300);
  CircuitPlayground.playTone(350, 300); 
  CircuitPlayground.playTone(390, 300); 
  CircuitPlayground.playTone(440, 300);
  CircuitPlayground.playTone(290, 200);
  CircuitPlayground.playTone(292, 200);
  CircuitPlayground.playTone(290, 200);
  CircuitPlayground.playTone(292, 200);
  CircuitPlayground.playTone(290, 200);
  CircuitPlayground.playTone(292, 200);
  CircuitPlayground.playTone(490, 300);
  CircuitPlayground.playTone(525, 400);
  CircuitPlayground.playTone(290, 200);
  CircuitPlayground.playTone(292, 200);
  CircuitPlayground.playTone(290, 200);
  CircuitPlayground.playTone(292, 200);
  CircuitPlayground.playTone(290, 200);
  CircuitPlayground.playTone(292, 200);
  CircuitPlayground.playTone(440, 300);
  CircuitPlayground.playTone(390, 300); 
  CircuitPlayground.playTone(350, 300); 
  CircuitPlayground.playTone(330, 300);
  }
   
   
   
}







No comments:

Post a Comment

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