Arduino Buzzer - how to make melodies/songs ?


hi team, :)

i have buzzer attached arduino uno.

i want know there tool making songs,melodies etc. super mario etc.

i have following code plays single melody now. dont know how make another.

code: [select]
'/*
* play simple tune using piezzo
* based on example created tom igoe
* http://arduino.cc/en/tutorial/tone
*/

// make sure file pitches.h placed in same folder sketch
#include "pitches.h"

// piezzo element connected arduino pin 12 , ground
const int buzzerpin = 13;

// array notes in melody (see pitches.h reference)
int melody[] = {note_a4, note_a4, note_a4, note_f4, note_c5, note_a4, note_f4, note_c5, note_a4, note_e5, note_e5, note_e5, note_f5, note_c5, note_a4, note_f4, note_c5, note_a4};

// array note durations: quarter note has duration of 4, half note 2 etc.
int durations[] = {4, 4, 4, 5, 16, 4, 5, 16, 2, 4, 4, 4, 5, 16, 4, 5, 16, 2};

int tempo = 120; // tempo melody expressed in beats per minute (bpm)

void setup() {
  playtune(melody, durations, tempo);
}

void loop() {
  // no need repeat melody.
}

void playtune(int notes[], int durations[], int bpm)
{
  int tunesize = sizeof(melody) / sizeof(int);
 
  // iterate on notes of tune:
  (int thisnote = 0; thisnote < tunesize; thisnote++) {

    // details on calculating note duration using tempo , note type,
    // see http://bradthemad.org/guitar/tempo_explanation.php.
    // quarter note @ 60 bpm lasts 1 second , @ 120 bpm - half second.
   
    int noteduration = (int)((1000 * (60 * 4 / bpm)) / durations[thisnote] + 0.);
    tone(buzzerpin, notes[thisnote],noteduration);

    // distinguish notes, set minimum time between them.
    // note's duration + 20% seems work well:
    int pausebetweennotes = noteduration * 1.20;
    delay(pausebetweennotes);
    // stop tone playing:
    notone(buzzerpin);
  }
}

what kind of buzzer have?

can read sheet music? you'll need in order able translate melody notes play on arduino.


Arduino Forum > Using Arduino > Programming Questions > Arduino Buzzer - how to make melodies/songs ?


arduino

Comments

Popular posts from this blog

Connecting Raspberry Pi 2 to P10(1R)-V706 LED Dot Matrix - Raspberry Pi Forums

TypeError: <unknown> is not a numpy array - Raspberry Pi Forums

datso and removing imagetitle - Joomla! Forum - community, help and support