#include <Servo.h>
#include <Adafruit_Circuit_Playground.h>
#include <Adafruit_CircuitPlayground.h>
/*
* NIME Undertale Music Box - Niles Garcia
*/
Servo srv; //State servo object, this allows you to control the servo
int ledPin = 10;
int readVal = 0;
int led = 0
void setup() {
Serial.begin(9600); //setup code here to run once
delay(1000);
CircuitPlayground.begin();
srv.attach(2);
pinMode(led, OUTPUT);
}
void loop() {
if(CircuitPlayground.leftButton()) { // The left button will play a song when pressed, song is called Megalovania
CircuitPlayground.playTone(587.33,120); //found each music note to hz conversion online
CircuitPlayground.playTone(587.33,120);
CircuitPlayground.playTone(1174.66,120);
CircuitPlayground.playTone(880,230);
CircuitPlayground.playTone(830.61,150);
CircuitPlayground.playTone(783.99,150);
CircuitPlayground.playTone(698.46,150);
CircuitPlayground.playTone(587.33,110);
CircuitPlayground.playTone(698.46,110);
CircuitPlayground.playTone(783.99,110);
}
else if (digitalRead(CPLAY_SLIDESWITCHPIN)) { // Switch that rotates servo for acoustics
srv.write(200); // Moves the servo to 200 degrees
delay(500); // Waits for it to move to it's new position
srv.write(0); // Moves the servo to 0 degrees
delay(500); // Waits for it to move to it's new position
}
readVal = analogRead(0);
led = map(readVal, 0, 1024, 0, 255);
analogWrite(ledPin, led);//read the value of light around and map it for use
}
14 March 2021
NIME PROJECT: Undertale Music Box
My project is very simple in concept. It is simply a music box that plays a song from one of my favorite games. It makes use of three different switches to control different parts of the box. What I like to do first is set the mood, and use the potentiometer to turn on the blue light in the eye of the character. Then I mapped the left button to play that characters theme song from the game. Lastly, I used a servo to raddle inside of the box and make an interesting acoustic sound that fits the mood and tempo of the box. The idea started with the song, once I had that song in my code, I knew I had to theme the box after that character somehow. Making the song was my favorite part. It was cool to find out that there is a chart online that shows you the hertz value for a specific musical notes, so that made it a lot easier to make the map the song out in the code. I was tempted to add a continuation of the song in the code but I didn't want it to go on for too long. Can you think of another way to make my box sound/look more interesting?
Labels:
nime
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.