20 March 2022

NIME Project Team 21: DJ Station


For this project, we built a small DJ station. We wanted to make all control available on the top of the box. We made two paper pipes and paper poles to extend to the button control. We cut a hole at the back of the box to make the power cables run through easily. That way it would be easier to connect the circuit playground to the power source. we then placed the potentiometer control on the top of the box so that the user would have easier control. The purpose of the potentiometer was so that the user can control the play speed of the song. As an indicator, we used the neo pixel lights to help indicate the key change and the speed change. To better see the change we cut a square hole on the top of the box to let the user see the pixel lights. The right button is used as the on and off switch for the system. The system will then start playing the first verse of the song Twinkle Twinkle Little Star. The left button is used to change the tone of the keys being played. Every time the user presses the left button, the song will then change to a different tone key. Once the song reaches the highest or the lowest key, it will then change the key to the opposite direction. The servo is hidden in the box. with a small metal pole attached to the servo. The purpose of the servo is to hit on the side of the box So that it can make a rhythmic acoustic sound every time the system plays a note. We would like some feedback on the use of the Servo. It serves as drum beats at the moment. What are other ways that the Servo could have worked better for the system?


Project Script:

#include <Servo.h> #include <Adafruit_CircuitPlayground.h> #include <Adafruit_Circuit_Playground.h> //Globe variables float music[] = {261.63, 261.63, 392, 392, 440, 440, 392}; // Music note array of the first verse of the song "Twinkle, Twinkle, Little Star" int key = 0; int keyChange = 50; int playSpeed = 250; int speedChange = -50; int inc = 1; int pos = 0; Servo myServo; int musicOn = 0; int musicLoop = 0; int firstLight = 1; void setup() { // put your setup code here, to run once: pinMode(4, INPUT_PULLDOWN); //Left button pinMode(5, INPUT_PULLDOWN); //Right button //Init Serial Serial.begin(9600); //Init CPE library CircuitPlayground.begin(); myServo.attach(A3); } void loop() { // Press right button if (digitalRead(5)) { delay(100); musicOn = 1; //Variable to control on/off the song. } if (!digitalRead(5) && musicOn == 1) { //Release the button and start to play the music playMusic(); // Calling the playmusic function delay(100); } if (!musicOn) { // When music is off, turn off all the pixels. CircuitPlayground.clearPixels(); firstLight = 1; } } void playMusic() { for (int i = 0; i < 7; i++) { // Play the notes in the array. int potPin = analogRead(A6); //Reading the analog signal from the potentiometer int playSpeed = map(potPin, 0, 950, 100, 350); // mapping the analog reading to playspeed. CircuitPlayground.clearPixels(); CircuitPlayground.setPixelColor(key / 50 + 2, 0, 127, 0); // light up the relative neopixel to indicate the key of the song CircuitPlayground.setPixelColor((playSpeed - 250) / 50 + 8, 0, 0, 127); // light up the relative neopixel to indicate the playspeed of the song if (digitalRead(4)) { //Press the left button to change the key key += keyChange; if (key == 100) { // If reaches the highest key, start to lower the key. keyChange = -50; } if (key == -100) { // If reaches the lowest key, start to raise the key. keyChange = 50; } } if (digitalRead(5) && musicOn == 1) { //If right button is pressed, stop the song. musicOn = 0; CircuitPlayground.clearPixels(); } if (pos == 0) { //Move the servo position from 0 to 45 degree. inc = 45; } if (pos == 45) { //Move the servo position from 45 to 0 degree. inc = -45; } //Set Servo position. When hit on the side of a box, make a beat. pos += inc; myServo.write(pos); // Play a note. CircuitPlayground.playTone(music[i] + key, playSpeed, false); } }






No comments:

Post a Comment

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