Aller au contenu


Photo

Petite melodie


  • Veuillez vous connecter pour répondre
Aucune réponse à ce sujet

#1 microrupteurman2

microrupteurman2

    Pilier du forum

  • Membres
  • PipPipPipPipPip
  • 2 041 messages
  • Gender:Male
  • Location:33
  • Interests:Tout

Posté 07 mars 2013 - 08:38

Trouvé en surfant sur le net :)

Buzzer sur pin 10 et GND.


/*
*By Gnieark [url="http://blog-du-grouik.tinad.fr/"]http://blog-du-grouik.tinad.fr/[/url] (le code, pas la musique)
*Faites ce que vous voulez du code, par contre pour la musique, 
*Voyez avec son auteur, je n'ai aucun droit là dessus,
*Mais c'est vous qui allez la charger sur la puce de votre arduino.
*Pas moi
*
*Un peu de culture au passage:
*Quand on passe d'un octave à celui au dessus, on double la fréquence de l'onde sonore.
*A=La, B=Si etc....
*/
int speakerPin = 10;
char names[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g'};
int tones[] = { 110, 123, 131, 147, 165, 175, 196 };
int tonesDiese[] = {117,0,139,156,0,185,208};
int tempo = 120;//double croche

void playNote(char note, int octave, int duration, boolean diese=false) {
  // play the tone corresponding to the note name
    int i=0;
    while((names[i]!=note) && (i<7)){
     i++; 
    }
    if (diese) {
      tone(speakerPin,tonesDiese[i] * octave, duration * tempo);
    }else{
      tone(speakerPin,(tones[i] * octave), duration * tempo);
    }
    delay(duration * tempo);
    noTone(speakerPin);
}

void setup() {
  pinMode(speakerPin, OUTPUT);
  
  //intro
    playNote('d',3,1,true);
  playNote('e',3,1,false);
  playNote('f',3,1,true);
  delay(tempo);
  playNote('b',4,1,false);
  playNote('e',3,1,false);
  playNote('d',3,1,true);
  playNote('e',3,1,false);
  playNote('f',3,1,true);
  playNote('b',4,1,false);
  playNote('d',4,1,true);
  playNote('e',4,1,false);
  playNote('d',4,1,true);
  playNote('a',4,1,true);
  playNote('b',4,1,false);
  delay(tempo);
 
  playNote('f',3,1,true); 
 delay(tempo);
   playNote('d',3,1,true);
  playNote('e',3,1,false);
  delay(tempo);
    playNote('f',3,1,true);
   delay(tempo);
    playNote('b',4,1,false);
    playNote('c',4,1,true);
   playNote('a',4,1,true);
   playNote('b',4,1,false);
   playNote('c',4,1,true);
   playNote('e',4,1,false);
   playNote('f',4,1,true);
   playNote('e',4,1,false);
   playNote('c',4,1,true);
}
void loop() {
  playNote('f',3,1,true);
  delay(tempo);
  playNote('g',3,1,true);
  delay(tempo);
  playNote('d',3,1,true);
  playNote('d',3,1,true);
  delay(tempo);
  playNote('b',3,1,true);
  playNote('d',3,1,false);
  playNote('c',3,1,true);
  playNote('b',3,1,false);
  delay(tempo);
  playNote('b',3,1,false);
  delay(tempo);
  playNote('c',3,1,true);
  delay(tempo);

  
  playNote('d',3,1,false);
  delay(tempo);
  playNote('d',3,1,false);
  playNote('c',3,1,true);
  playNote('b',3,1,false);
  playNote('c',3,1,true);
  playNote('d',3,1,true);
  playNote('f',3,1,true);
  playNote('g',3,1,true);
  playNote('d',3,1,true);
  playNote('f',3,1,true);
  playNote('c',3,1,true);
  playNote('d',3,1,true);
  playNote('b',3,1,false);
  playNote('c',3,1,true);
  playNote('b',3,1,false);
  
  playNote('d',3,1,true);
  delay(tempo);
  playNote('f',3,1,true);
  delay(tempo);
  playNote('g',3,1,true);
  playNote('d',3,1,true);
  playNote('f',3,1,true);
  playNote('c',3,1,true);
  playNote('d',3,1,true);
  playNote('b',3,1,false);
  playNote('c',3,1,true);
  playNote('d',3,1,true);
  playNote('d',3,1,false);
  playNote('c',3,1,true);
  playNote('b',3,1,false);
  playNote('c',3,1,true);
  
  playNote('d',3,1,false);
  delay(tempo);
  playNote('b',3,1,false);
  playNote('c',3,1,true);
  playNote('d',3,1,true);
  playNote('f',3,1,true);
  playNote('c',3,1,true);
  playNote('d',3,1,false);
  playNote('c',3,1,true);
  playNote('b',3,1,false);
  playNote('c',3,1,true);
  delay(tempo);
  playNote('b',3,1,false);
  delay(tempo);
  playNote('c',3,1,true);
  delay(tempo);
  
  playNote('f',3,1,true);
  delay(tempo);
  playNote('g',3,1,true);
  delay(tempo);
  playNote('c',3,1,true);
  playNote('d',3,1,true);
  delay(tempo);
  playNote('c',3,1,true);
  playNote('d',3,1,false);
  playNote('c',3,1,true);
  playNote('b',3,1,false);
  delay(tempo);
  playNote('b',3,1,false);
  delay(tempo);
  playNote('c',3,1,true);
  delay(tempo);
  
  
  playNote('d',3,1,false);
  delay(tempo);
  playNote('d',3,1,false);
  playNote('c',3,1,true);
  playNote('b',3,1,false);
  playNote('c',3,1,true);
  playNote('d',3,1,true);
  playNote('f',3,1,true);
  playNote('g',3,1,true);
  playNote('d',3,1,true);
  playNote('f',3,1,true);
  playNote('c',3,1,true);
  playNote('d',3,1,true);
  playNote('b',3,1,false);
  playNote('c',3,1,true);
  playNote('b',3,1,false); 
 
 
  playNote('d',3,1,true);
  delay(tempo);
  playNote('f',3,1,true);
  delay(tempo);
  playNote('g',3,1,true);
  playNote('d',3,1,true);
  playNote('f',3,1,true);
  playNote('c',3,1,true);
  playNote('d',3,1,true);
  playNote('b',3,1,false);
  playNote('c',3,1,true);
  playNote('d',3,1,true);
  playNote('d',3,1,false);
  playNote('b',3,1,false);
  playNote('c',3,1,true);
  
  
  playNote('d',3,1,false);
  delay(tempo);
  playNote('b',3,1,false);
  playNote('c',3,1,true);
  playNote('d',3,1,true); 
  playNote('f',3,1,true);
  playNote('c',3,1,true);
  playNote('d',3,1,false);
  playNote('c',3,1,true);
  playNote('b',3,1,false);
  playNote('c',3,1,true);
  delay(tempo);
  playNote('b',3,1,false);
  delay(tempo);
  playNote('b',3,1,false);
  delay(tempo);
  
  
  playNote('b',3,1,false);
  delay(tempo);
  playNote('f',2,1,true); 
  playNote('g',2,1,true);
  playNote('b',3,1,false);
  delay(tempo);
  playNote('f',2,1,true); 
  playNote('g',2,1,true);
  playNote('b',3,1,false);
  playNote('c',3,1,true);
  playNote('d',3,1,true);
  playNote('b',3,1,false);
  playNote('e',3,1,false);
  playNote('d',3,1,true);
  playNote('e',3,1,false);
  playNote('f',3,1,true);
  
  
  playNote('b',3,1,false);
  delay(tempo);
  playNote('b',3,1,false);
  delay(tempo);
   playNote('f',2,1,true); 
  playNote('g',2,1,true);
  playNote('b',3,1,false);
  playNote('f',2,1,true); 
  playNote('e',3,1,false);
  playNote('d',3,1,true);  
  playNote('c',3,1,true); 
  playNote('b',3,1,false);
  playNote('e',2,1,false);
  playNote('d',2,1,true); 
  playNote('e',2,1,false);
  playNote('f',2,1,true);

  playNote('b',3,1,false);
  delay(tempo);
  playNote('f',2,1,true); 
  playNote('g',2,1,true);
  playNote('b',3,1,false);
  delay(tempo);
  playNote('f',2,1,true); 
  playNote('g',2,1,true);
  playNote('b',3,1,false);
  playNote('b',3,1,false);
  playNote('c',3,1,true);
  playNote('d',3,1,true);
  playNote('b',3,1,false);
  playNote('f',2,1,true);
  playNote('g',2,1,true);
  playNote('f',2,1,true);
  
  playNote('b',3,1,false);
  delay(tempo);
  playNote('b',3,1,false);
  playNote('a',3,1,true);
  playNote('b',3,1,false);
  playNote('f',2,1,true); 
  playNote('g',2,1,true);
  playNote('b',3,1,false);
  playNote('e',3,1,false);
  playNote('d',3,1,true);
  playNote('e',3,1,false);
  playNote('f',3,1,true);
  playNote('b',3,1,false);
  delay(tempo);
  playNote('a',3,1,true);
  delay(tempo);
  
  playNote('b',3,1,false);
  delay(tempo);
  playNote('f',2,1,true); 
  playNote('g',2,1,true);
  playNote('b',3,1,false);
  delay(tempo);
  playNote('f',2,1,true); 
  playNote('g',2,1,true);
  playNote('b',3,1,false);
  playNote('c',3,1,true);
  playNote('d',3,1,true);
  playNote('b',3,1,false);
  playNote('e',3,1,false);
  playNote('d',3,1,true);
  playNote('e',3,1,false);
  playNote('f',3,1,true);
  
  playNote('b',3,1,false);
  delay(tempo);
  playNote('b',3,1,false);
  delay(tempo);
  playNote('f',2,1,true); 
  playNote('g',2,1,true);
  playNote('b',3,1,false);
  playNote('f',2,1,true); 
  playNote('e',3,1,false);
  playNote('d',3,1,true); 
  playNote('c',3,1,true); 
  playNote('b',3,1,false);
  playNote('e',2,1,false);
  playNote('d',2,1,true);
  playNote('e',2,1,false);
  playNote('f',2,1,true);
  
  playNote('b',3,1,false);
  delay(tempo);
  playNote('f',2,1,true); 
  playNote('g',2,1,true);
  playNote('b',3,1,false);
  delay(tempo);
  playNote('f',2,1,true); 
  playNote('g',2,1,true);
  playNote('b',3,1,false);
  playNote('b',3,1,false);
  playNote('c',3,1,true);
  playNote('d',3,1,true);
  playNote('b',3,1,false);
  playNote('f',2,1,true); 
  playNote('g',2,1,true);
  playNote('f',2,1,true);
 
  playNote('b',3,1,false);
  delay(tempo);
  playNote('b',3,1,false);
  playNote('a',3,1,true);
  playNote('b',3,1,false);
  playNote('f',2,1,true); 
  playNote('g',2,1,true);
  playNote('b',3,1,false);
  playNote('e',3,1,false);
  playNote('d',3,1,true);
  playNote('e',3,1,false);
  playNote('f',3,1,true);
  playNote('b',3,1,false);
  delay(tempo);
  playNote('c',3,1,true);
  delay(tempo);
}



 
 
 




0 utilisateur(s) li(sen)t ce sujet

0 members, 0 guests, 0 anonymous users