INSPIRATION
On the internet, there’s a way of making people listen to a specific song, but in a new way every time. We decided to use Arduino to do just that.
IDEA
A switch to start playing the song and stop playing the song.
A potentiometer to fasten or slow down the tempo of the song.
BREADBOARD
VIDEO DEMO
CODES
int speaker_pin = 2; bool Switch = LOW; volatile int tone_length = 100; // determines tempo // Parts 1 and 2 (Intro) int melody[] = { 554, 622, 622, 698, 831, 740, 698, 622, 554, 622, -1, 415, 415, 554, 622, 622, 698, 831, 740, 698, 622, 554, 622, -1, 415, 415, -1, 277, 277, 277, 277, 311, -1, 261, 233, 208, -1, 233, 233, 261, 277, 208, 415, 415, 311, -1, 233, 233, 261, 277, 233, 277, 311, -1, 261, 233, 233, 208, -1, 233, 233, 261, 277, 208, 208, 311, 311, 311, 349, 311, 277, 311, 349, 277, 311, 311, 311, 349, 311, 208, -1, 233, 261, 277, 208, -1, 311, 349, 311, -1, 277, 277, 277, 277, 311, -1, 261, 233, 208, -1, 233, 233, 261, 277, 208, 415, 415, 311, -1, 233, 233, 261, 277, 233, 277, 311, -1, 261, 233, 233, 208, -1, 233, 233, 261, 277, 208, 208, 311, 311, 311, 349, 311, 277, 311, 349, 277, 311, 311, 311, 349, 311, 208, -1, 233, 261, 277, 208, -1, 311, 349, 311, 466, 466, 415, 415, 698, 698, 622, 466, 466, 415, 415, 622, 622, 554, 523, 466, 554, 554, 554, 554, 554, 622, 523, 466, 415, 415, 415, 622, 554, 466, 466, 415, 415, 698, 698, 622, 466, 466, 415, 415, 831, 523, 554, 523, 466, 554, 554, 554, 554, 554, 622, 523, 466, 415, -1, 415, 622, 554, -1, 466, 466, 415, 415, 698, 698, 622, 466, 466, 415, 415, 622, 622, 554, 523, 466, 554, 554, 554, 554, 554, 622, 523, 466, 415, 415, 415, 622, 554, 466, 466, 415, 415, 698, 698, 622, 466, 466, 415, 415, 831, 523, 554, 523, 466, 554, 554, 554, 554, 554, 622, 523, 466, 415, -1, 415, 622, 554, -1 }; int rhythmn[] = { 6, 10, 6, 6, 1, 1, 1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); Serial.begin(9600); //while (digitalRead(3)); } void loop() { Switch = digitalRead(3); int note_delay; check_pot(); if (Switch == HIGH) { for (int i = 0 ; i < sizeof(rhythmn) ; i++) { if (melody[i] > 0) { check_pot(); note_delay = tone_length * rhythmn[i]; tone(speaker_pin, melody[i], note_delay); } delay(note_delay); delay(tone_length * 0.3); } delay(note_delay); noTone(speaker_pin); } } void check_pot() { tone_length = map(analogRead(A0) , 0 , 1023 , 10 , 200); }
CHALLENGES
It was a hassle trying to locate the frequencies of the notes and manipulate the duration intervals between each note.