NIME Project: Team 12
For our project, we created a NIME that, when you press a button, plays a note. There are three buttons and each one plays a different note. Originally, we were only going to include two buttons, as the assignment only requires two other inputs aside from the potentiometer. However, we opted to include a third button, as that would make it much easier to play better music with this NIME instrument. One plays an A note at the 4th octave (440), another plays the E note at the 5th octave (659.25), and the final third one plays an A note at the 5th octave (880). The note will play for about 10 milliseconds before it stops, or plays again if you hold the button. We have the buttons connecting to the Circuit Playground Bluefruit’s A1 (D6), A2 (D9), and A6 (D0) pins. Our servo connects to the Circuit Playground Bluefruit’s A3 (D10) pin while our potentiometer connects to the CPB’s A4 (D3) pin. You can use the CPB’s switch (D7) to switch the servo between two modes: one where the potentiometer controls the servo itself, and one where the potentiometer controls the speed at which the servo moves automatically. Do you think there is anything that we could've done better or more neatly? Regarding the enclosure, the coding, the notes used, or otherwise?
#include <Adafruit_CircuitPlayground.h>#include <Adafruit_Circuit_Playground.h>#include <Servo.h>/*** Created by Team 12 Mohammad Saadeh and Cody Hoscheid** Instructions: User can press the 3 buttons on the box to play 3 different tones to create a song while an acoustic* sound continues to play. The tones and servo acoustic sound can be controlled by the potentiometer which can be turned with the rotator button.***///variables for controlling servoServo ourServo;int pos = 0;int inc = 1;int cpepin = 7;int buttonpin = A4;int timer = 0;//440, 493.88, 523.25, 587.33, 659.25, 783.99, 880 frequency notesvoid setup() {// put your setup code here, to run once:Serial.begin(9600);delay(1000);CircuitPlayground.begin();//Servo attached to A3 PINourServo.attach(10);//A3//Buttons attached to bluefruitpinMode(13, OUTPUT);pinMode(4, INPUT_PULLDOWN);pinMode(5, INPUT_PULLDOWN);pinMode(6, INPUT_PULLUP);pinMode(9, INPUT_PULLUP);pinMode(0, INPUT_PULLUP);}void loop() {// put your main code here, to run repeatedly://Reads button and rotates servo with potentiometerif(millis() > timer + 15) {if(pos == 0) inc = 1;if(pos == 180) inc = -1;ourServo.write(pos);pos += inc;timer = millis();}int button = analogRead(buttonpin);if(digitalRead(cpepin)){//first stateint rot = map(button, 0, 1023, 0, 180);ourServo.write(rot);}else{//second state//Edits the rate the servo rotatesif (pos == 0) inc = 1;if(pos == 180) inc = -1;pos += inc;ourServo.write(pos);int rate = map(button,0, 1023, 1, 100);delay(rate);Serial.println(button);}digitalWrite(13, digitalRead(4));//plays the tone on the buttons on the breadboardif(!digitalRead(6)) {CircuitPlayground.playTone(400, 100);}if(!digitalRead(9)) {CircuitPlayground.playTone(880, 100);}if(!digitalRead(0)) {CircuitPlayground.playTone(659.25, 100);}}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.