20 March 2022

NIME14

 





Our project was that of a sound box, which was to have a few buttons that would play sounds on being pressed.  One of the buttons would toggle on and off a servo that would create an acoustic sound by being used in conjunction with a coca cola soda can.  The other buttons would each play a digital sound using the onboard speaker of the CPB.  We also had variable resistors in the form of potentiometers that would control speed of the sounds occurring in the box.  We had a couple of problems throughout the project with components not reacting the way they are supposed to like buttons not working when wired correctly and the servo being able to rotate 360 degrees when they are only supposed to physically be able to rotate between 0 and 180 degrees, and the potentiometer at the max and min values would have unexpected effects on the system, but in the end, we made them work.  The buttons had a 1:1 mapping as they each would play one sound, while the potentiometers have a many:1 mapping as they have 0 – 1023 values mapped to a smaller scale of values and thus many of the input values will equal a single output value instead of 1:1.  The placement of components could be better so that the feedback would be more predictable, one signifier we had was having the button that controls the servo apart from the buttons that play the digital sounds as their function was different.

Are there any components we could add that would help as signifiers to better know what the existing components do without having to mess around and find out? 


#include <Servo.h>

#include <Adafruit_CircuitPlayground.h>

#include <Adafruit_Circuit_Playground.h>

 

int Digital1 = 3;

int Digital2 = 2;

int Digital3 = 0;

int Digital4 = 1;

int PlayTime = 160;

 

Servo AcousticServo;

int dt = 50;

int aCurrent = 0;

int aPrevious = 0;

bool ServoState = false;

int ServoSpeed = 0;

int DigSoundTime = 10;

int DigSoundPot = 10;

 

int pos = 0;

int inc = 2;

int timer = 0;

 

void setup() {

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

    AcousticServo.attach(10);

    pinMode(12 , INPUT_PULLUP); //Button for Servo

    pinMode(6 , INPUT); //Potentiometer for Servo Speed

    pinMode(Digital1 , INPUT_PULLUP); //Digital Sound 1

    pinMode(Digital2 , INPUT_PULLUP); //Digital Sound 2

    pinMode(Digital3 , INPUT_PULLUP); //Digital Sound 3

    pinMode(Digital4 , INPUT_PULLUP); //Digital Sound 4

    pinMode(9 , INPUT); //Potentiometer for Digital Sound Speed Offset

 

    Serial.begin(9600);

    delay(1000);

    CircuitPlayground.begin();

}

 

void loop() {

    // put your main code here, to run repeatedly:

    ServoSpeed = analogRead(6); //get Servo speed

 

    //Switch on and off servo

    aCurrent = digitalRead(12);

    if(aCurrent == 1 && aPrevious == 0){

        if(!ServoState){

            ServoState = true;

            Serial.println("On");

        } else {

            ServoState = false;

            Serial.println("Off");

        }

        delay(dt);

    }

    aPrevious = aCurrent;

 

    //Tell servo what to do if on

    if(ServoState){

        if(pos == 0) inc = 5;

        if(pos == 180) inc = -5;

        pos += inc;

        AcousticServo.write(pos);

        int rate = map(ServoSpeed, 0, 1023, 1, 40);

        delay(rate);

    }

    

    //Get Digital Sound Potentiometer input and map it to a usable range

    DigSoundPot = analogRead(9);

    DigSoundTime = map(DigSoundPot, 0, 1023, 1, 200);

 

    //Check for button presses and play sound if pressed

    if(digitalRead(Digital1) == 1){

        CircuitPlayground.playTone(1046 , DigSoundTime);

    }

 

    if(digitalRead(Digital2) == 1){

        CircuitPlayground.playTone(1318, DigSoundTime);

    }

 

    if(digitalRead(Digital3) == 1){

        CircuitPlayground.playTone(1568, DigSoundTime);

    }

 

    if(digitalRead(Digital4) == 1){

        CircuitPlayground.playTone(1976, DigSoundTime);

    }

}


No comments:

Post a Comment

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