Capstone project

  • I wanted to make a music player but it didn’t come out the way I wanted it to.
  • I wanted to make it because I enjoy music and I thought it would be cool to include something I enjoy with the Arduino.
  • An input I used was the Potentiometer
  • An Output I used was the Piezo
  • (This is the code I used)

int speakerpin=9; //Variable to store pin of LED
int potentPin=A0; //Variable to store pin of potentiometer
int potentValue=0; //Variable to store last known value of potentiometer
int brightnessValue=0; //Variable to store LED brightness
int tones[] = {174.6, 277.2,415.3,311.1,349.2,523.3,554.4,311.1,622.3,349.2,523.3,415.3,554.4,622.3,698.5,622.3,174.6,261.6, };
void setup() {
// put your setup code here, to run once:
pinMode(speakerpin, OUTPUT); //Setup LED pin for output
}

void loop() {
// put your main code here, to run repeatedly:
potentValue=analogRead(potentPin); //Read the value of the potentiometer pin
brightnessValue=map(potentValue,0,1023,0,255); //Map the potentiometer value to a brightness
if(potentValue<15){
tone(speakerpin, tones[0]);
}
else if (potentValue<30){
tone(speakerpin, tones[1]);
}
else if (potentValue<45){
tone(speakerpin, tones[2]);
}
else if (potentValue<60){
tone(speakerpin, tones[3]);
}
else if (potentValue<85){
tone(speakerpin, tones[4]);
}
else if (potentValue<100){
tone(speakerpin, tones[5]);
}
else if (potentValue<115){
tone(speakerpin, tones[6]);
}
else if (potentValue<130){
tone(speakerpin, tones[7]);
}
else if (potentValue<145){
tone(speakerpin, tones[8]);
}
else if (potentValue<160){
tone(speakerpin, tones[9]);
}
else if (potentValue<175){
tone(speakerpin, tones[10]);
}
else if(potentValue<190){
tone(speakerpin, tones[11]);
}
else if (potentValue<205){
tone(speakerpin, tones[12]);
}
else if(potentValue<220){
tone(speakerpin, tones[13]);
}
else if(potentValue<235){
tone(speakerpin, tones[14]);
}
else if(potentValue<250){
tone(speakerpin, tones[15]);
}
else if(potentValue<265){
tone(speakerpin, tones[16]);
}
else if(potentValue<280){
tone(speakerpin, tones[17]);

photo-on-11-10-16-at-5-04-pm

Submit a Comment