14 March 2021

NIME, Music Box

 


For this project, I was attempting to make a music box. I got the music aspect of it down but I was never able to get the potentiometer to work in accordance with the light, I would always move the servo. I decided to in the end leave out the code with the mapping of the potentiometer. The end result of the music box this that at the press of one button it can shake a bag of plastic blocks to mimic a sound of chimes and if you press another button it will play a scale and with every note played the LED also blinks.

#include <Servo.h>

#include <Adafruit_CircuitPlayground.h>

#include <Adafruit_Circuit_Playground.h>

#define LED 10

 

Servo myservo;

int pot = 0;

 

void setup() {

  // put your setup code here, to run once:

  myservo.attach(A3);

  pinMode(LED, OUTPUT);

  pinMode(A4, INPUT);

  delay(1000);

}

 

void loop()

{

  //... This is where I tryed to make the potentiometer

//pot = analogRead(A4);

//Serial.println(pot);

//pot = map(pot, 1, 1024,1, 10);

//analogWrite(A0,pot);

 

if (digitalRead(CPLAY_RIGHTBUTTON)) //Play a scale

  {

    CircuitPlayground.playTone(100, 200);

    CircuitPlayground.playTone(300, 200);

    CircuitPlayground.playTone(500, 200);

    CircuitPlayground.playTone(700, 200);

    CircuitPlayground.playTone(800, 200);

    CircuitPlayground.playTone(700, 200);

    CircuitPlayground.playTone(500, 200);

    CircuitPlayground.playTone(300, 200);

    CircuitPlayground.playTone(100, 200);

    CircuitPlayground.playTone(500, 200);

    CircuitPlayground.playTone(700, 200);

    CircuitPlayground.playTone(500, 200);

    CircuitPlayground.playTone(100, 200);

  }

if (digitalRead(CPLAY_LEFTBUTTON)) // Shake the bag of Legos

  {

    myservo.write(180);

    delay(150);

    myservo.write(0);

    delay(150);

  }

}





No comments:

Post a Comment

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