NIME TEAM 11
For this project, I wanted to create something akin to a piano keyboard. The goal was to play a range of notes with the button and use the instruments attached to the fan on the servo to produce background noise in addition to the notes being played.
So for the notes I chose the main ones from the song Runaway by Kanye West. It features a multitude of E sharps, C sharps, etc. I put those frequencies into an array in the IDE and allowed it to be played in full at the press of a button. I wanted to be able to cycle through them somehow but couldn't exactly figure out the code for that in time so I just settled for the whole range at one click of a button. The servo moves when turning the knob on the potentiometer. As it moves, the bells stringed to it jingle off the board and each other to produce a jingling sound in the background of the notes.
//NIME Project by Justice Anderson & Jared Toavs//DIG3602C Professor Mosher#include <Servo.h>#include <Adafruit_CircuitPlayground.h>#include <Adafruit_Circuit_Playground.h>//servoServo myServo;int timer = 0;int inc = 1;//potentiometer variablesint potpin = A1; // analog pin used to connect the potentiometerint val; // variable to read the value from the analog pin//array of notes in the song Runaway by Kanye Westfloat notes[] = {261.63, 261.63, 261.63, 261.63, 261.63, 261.63, 261.63, 261.63,261.63, 261.63, 261.63, 261.63, 261.63, 261.63, 261.63, 311.127, 311.127, 311.127,277.18, 277.18, 466.164, 466.164, 261.63};void setup() {// put your setup code here, to run once:CircuitPlayground.begin();Serial.begin(9600);delay(1000);//servo codemyServo.attach(10); //A3pinMode(4, INPUT_PULLDOWN); //left buttonpinMode(5, INPUT_PULLDOWN); //right button}void loop() {val = analogRead(potpin); // gets the value of the potentiometerval = map(val, 0, 1023, 0, 180); // converts it ton a number usable by the servoif(millis() > timer + 15) {if(val == 0) inc = 1;if(val == 180) inc = -1;myServo.write(val); // the servo is set to the stored value from the potentiometerval += inc;timer = millis();}if(digitalRead(5)) { // checks if button is clickedfor(int i = 0; i < 23; i++) { // when button is clicked it loops through until it hits 23 CircuitPlayground.playTone(notes[i], 500); // plays the notes in the notes array}}}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.