/* ################################################################# # Programme arduino : Permet de jouer un mélodie monophonique # # sur un buzzer relié a une sortie. # ################################################################# */ /* Definition des duree des notes */ #define NOIRE 1.000 #define BLANCHE 2.0*NOIRE #define RONDE 4.0*NOIRE #define CROCHE NOIRE/2.0 #define DOUBLE_CROCHE NOIRE/4.0 #define QUADRUPLE_CROCHE NOIRE/8.0 /* Definition des frequences des notes de musique */ #define MUTE 0 #define DO_3 261.63 #define DO_D_3 277.18 #define RE_3 293.66 #define RE_D_3 311.13 #define MI_3 329.63 #define FA_3 349.23 #define FA_D_3 369.99 #define SOL_3 392 #define SOL_D_3 415.3 #define LA_3 440 #define LA_D_3 466.16 #define SI_3 493.88 #define DO_4 523.25 #define DO_D_4 554.37 #define RE_4 587.33 #define RE_D_4 622.25 #define MI_4 659.26 #define FA_4 698.46 #define FA_D_4 739.99 #define SOL_4 783.99 #define SOL_D_4 830.61 #define LA_4 880 #define LA_D_4 932.33 #define SI_4 987.77 #define DO_5 1046.5 /* dezfinition des PINs */ #define PIN_BUZZER 12 /* Melodie - Berceuse Zelda */ float melodie[]={ 500, // durée de la noire en ms SI_3, BLANCHE, RE_4, NOIRE, LA_3, BLANCHE, SOL_3, CROCHE, LA_3, CROCHE, SI_3, BLANCHE, RE_4, NOIRE, LA_3, BLANCHE, MUTE, NOIRE, SI_3, BLANCHE, RE_4, NOIRE, LA_4, BLANCHE, SOL_4, NOIRE, RE_4, BLANCHE, DO_4, CROCHE, SI_3, CROCHE, LA_4, BLANCHE, MUTE, NOIRE, SI_3, BLANCHE, RE_4, NOIRE, LA_3, BLANCHE, SOL_3, CROCHE, LA_3, CROCHE, SI_3,BLANCHE, RE_4, NOIRE, LA_3, BLANCHE, MUTE, NOIRE, SI_3, BLANCHE, RE_4, NOIRE, LA_4, BLANCHE, SOL_4, NOIRE, RE_4, BLANCHE, RE_4, BLANCHE, MUTE, BLANCHE, RE_4, BLANCHE, DO_4, CROCHE, SI_3, CROCHE, DO_4, CROCHE, SI_3, CROCHE, SOL_3, BLANCHE, DO_4, BLANCHE, SI_3, CROCHE, LA_3, CROCHE, SI_3, CROCHE, LA_3, CROCHE, MI_3, BLANCHE, RE_4, BLANCHE, DO_4, CROCHE, SI_3, CROCHE, DO_4, CROCHE, SI_3, CROCHE, SOL_3, NOIRE, RE_4, NOIRE, SOL_4, BLANCHE, SOL_4, BLANCHE }; /* Initialisation */ void setup(){ pinMode(PIN_BUZZER, OUTPUT); } /* Programme Principal */ void loop(){ int indexNote; int nombreNote = sizeof(melodie) / (2*sizeof(float)); int indexDerniereNote = nombreNote*2 - 1; int dureeNoire = melodie[0]; for( indexNote=1; indexNote<=indexDerniereNote; indexNote+=2){ if(melodie[indexNote] != MUTE){ tone(PIN_BUZZER, melodie[indexNote]); } delay(melodie[indexNote + 1] * dureeNoire); noTone(PIN_BUZZER); } }