Project: NIME
Team 16
William Correa Espitia and Dante Bondi
Our music box is divided into two different outputs, and one modifier. At the heart of the music box is the circuit playground express which is controlling the input and outputs. We have a servo connected to the CPE on A3 and its movement creates an acoustic output by hitting the bell and making it ring. The CPE has 2 physical button inputs that both play a distinct tone. There is also a breadboard that has a potentiometer being powered by a 9v battery connected to the breadboard. This potentiometer changes the pitch of the tone and allows you to create your own unique sounds and music with the two buttons that change pitch based on potentiometer and the servo jingling the bell in the back. The design of the box makes it easy to transport and is simple to use with the two inputs and the modifier. The potentiometer receives feedback and changes the output of the tone. One question that we would like peer review feedback on is should we implement a way to change the movement of the servo to match the tone and if we can do what type of changes and addition would we need to make to our code to implement it.
#include <Servo.h>
#include <Adafruit_CircuitPlayground.h>
#include <Adafruit_Circuit_Playground.h>
//Servo
Servo myServo;
//Variables
int potenLoc = 0;
int potenNum = 0;
int inc = 1;
int pos = 0;
int timer = 0;
//code that runs once on startup
void setup() {
Serial.begin(9600);
delay(15);
CircuitPlayground.begin();
myServo.attach(10); // Servo connected to A3
pinMode(5, INPUT_PULLDOWN); // right button press
pinMode(4, INPUT_PULLDOWN); // left button press
pinMode(13, OUTPUT);
}
//code that loops repeatedly
void loop() {
if (millis() > timer + 15) {
if (pos == 0) inc = 1;
if (pos == 180) inc = -1;
myServo.write(pos);
pos += inc;
timer = millis();
}
potenNum = analogRead(A1); // reads potentiometer input on A1
Serial.print(potenNum);
potenLoc = map(potenNum, 0, 1045, 0, 200); //potentiometer position mapped to the value that changes the tone
if (digitalRead(4)) {
left(potenLoc);
}
if (digitalRead(5)) {
right(potenLoc);
}
}
//========================================================================
void left(int potenMap) { // new sound based off potentiometer
CircuitPlayground.playTone(500-potenLoc,300);
}
void right(int potenMap) { // new sound based off potentiometer
CircuitPlayground.playTone(700-potenLoc,400);
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.