Play Smoke on the Water melody

I read at the bottom of this Play a Melody code that I can change the bars in the melody to 'smoke on the water'. i looked up the song's tabs on another site, but still don't know what bars I need or exactly how I need to change the code. Tabs are written in numbers. please help. :.

Play_Melody.ino (4.55 KB)

Try this... Yahoo | Mail, Weather, Search, Politics, News, Finance, Sports & Videos

i looked up the song's tabs on another site

What would this mean in English?

but still don't know what bars I need

That code plays some notes for some time. How that relates to bars is not clear. Perhaps, you are trying to play the music in a bar?

or exactly how I need to change the code

Change the values in the melody and beats arrays.

Tabs are written in numbers.

What tab? Your bar tab?

Guitar Tablature, I suspect. Fingering charts for guitarists.

I selected "what do i change in the code?". Hope that helps!

int melody[] = {  C,  b,  g,  C,  b,   e,  R,  C,  c,  g, a, C };

While declared as an integer array, the array symbols relating to notes are never defined or populated with values, moreover including tones.h is a mu point as you never make any call to a class in that library.
Middle C is 440Hz. Calculate each note in your scale in terms of time (1/f), where f = Frequency.

Quote from the Tone library reference(the include is Tone.h not tones.h).

tone()
 
Description
 
Generates a square wave of the specified frequency (and 50% duty cycle) on a pin. A duration can be specified, otherwise the wave continues until a call to noTone(). The pin can be connected to a piezo buzzer or other speaker to play tones.
 

Only one tone can be generated at a time. If a tone is already playing on a different pin, the call to tone() will have no effect. If the tone is playing on the same pin, the call will set its frequency.
 

Use of the tone() function will interfere with PWM output on pins 3 and 11 (on boards other than the Mega).
 

NOTE: if you want to play different pitches on multiple pins, you need to call noTone() on one pin before calling tone() on the next pin.
 

Syntax
 
tone(pin, frequency) 
tone(pin, frequency, duration)

this is all very good info. I'll take note, because i definitely want to accomplish this. Now I read "if i'm doing this in D play notes"

D F G
D F Ab G
D F G
F G

Now I know middle C is 440Hz (which i take is the frequency measured in Hz). "Calculate each note in your scale in terms of time (1/f), where f = frequency". What physics problem related to sound is this? Why do I want to calculate each note in terms of time when the tone() function wants to know parameters pin,frequency, and duration? Also, how would I calculate Ab or D for the matter? I just need one or two examples to get me started. Thx for voting! :fearful:

the code example provided in your post did not make any cal to tone lib, but used digital write commands, hence my comments.

flats are 1/3 under the fundamental.

I did some research for you
http://www.harpsatsang.com/harp_design/data/frequencies.html

it has a table of pitch frequencies.

Here's an example that makes a cellphone like warble

// info on alarm sound
 #include "pitch.h"

// notes in the melody
int thisNote = 0;
int noteDuration = 0;
int pauseBetweenNotes = 0;
int melody[] = {
NOTE_B5, NOTE_G5, NOTE_B5, NOTE_G5, NOTE_B5, NOTE_G5, NOTE_B5};
// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
12,12,12,12,12,12,4};

void setup(){
  // Buzzer section - connect pin D17 to speaker driver
    // create a warble once
    for (thisNote = 0; thisNote < 8; thisNote++) 
    {
      // to calculate the note duration, take one second 
      // divided by the note type.
      //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
      noteDuration = 1000/noteDurations[thisNote];
      noTone(17);       //apparent known bug - need this for the tone to play next.
      tone(17, melody[thisNote],noteDuration);
      // to distinguish the notes, set a minimum time between them.
      // using the note's duration + 10%:
      pauseBetweenNotes = noteDuration * 1.10;
      delay(pauseBetweenNotes);
      // stop the tone playing:
      noTone(17); 
    } 
  }
void loop(){}

store this as "pitch.h"

/*************************************************
 * Public Constants
 *************************************************/

#define NOTE_B0  31
#define NOTE_C1  33
#define NOTE_CS1 35
#define NOTE_D1  37
#define NOTE_DS1 39
#define NOTE_E1  41
#define NOTE_F1  44
#define NOTE_FS1 46
#define NOTE_G1  49
#define NOTE_GS1 52
#define NOTE_A1  55
#define NOTE_AS1 58
#define NOTE_B1  62
#define NOTE_C2  65
#define NOTE_CS2 69
#define NOTE_D2  73
#define NOTE_DS2 78
#define NOTE_E2  82
#define NOTE_F2  87
#define NOTE_FS2 93
#define NOTE_G2  98
#define NOTE_GS2 104
#define NOTE_A2  110
#define NOTE_AS2 117
#define NOTE_B2  123
#define NOTE_C3  131
#define NOTE_CS3 139
#define NOTE_D3  147
#define NOTE_DS3 156
#define NOTE_E3  165
#define NOTE_F3  175
#define NOTE_FS3 185
#define NOTE_G3  196
#define NOTE_GS3 208
#define NOTE_A3  220
#define NOTE_AS3 233
#define NOTE_B3  247
#define NOTE_C4  262
#define NOTE_CS4 277
#define NOTE_D4  294
#define NOTE_DS4 311
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_FS4 370
#define NOTE_G4  392
#define NOTE_GS4 415
#define NOTE_A4  440
#define NOTE_AS4 466
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_CS5 554
#define NOTE_D5  587
#define NOTE_DS5 622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5 740
#define NOTE_G5  784
#define NOTE_GS5 831
#define NOTE_A5  880
#define NOTE_AS5 932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6 1109
#define NOTE_D6  1175
#define NOTE_DS6 1245
#define NOTE_E6  1319
#define NOTE_F6  1397
#define NOTE_FS6 1480
#define NOTE_G6  1568
#define NOTE_GS6 1661
#define NOTE_A6  1760
#define NOTE_AS6 1865
#define NOTE_B6  1976
#define NOTE_C7  2093
#define NOTE_CS7 2217
#define NOTE_D7  2349
#define NOTE_DS7 2489
#define NOTE_E7  2637
#define NOTE_F7  2794
#define NOTE_FS7 2960
#define NOTE_G7  3136
#define NOTE_GS7 3322
#define NOTE_A7  3520
#define NOTE_AS7 3729
#define NOTE_B7  3951
#define NOTE_C8  4186
#define NOTE_CS8 4435
#define NOTE_D8  4699
#define NOTE_DS8 4978

I don't have a speaker handy but I think this will work. Change to the notes & durations you want to play.

I think I figured that stuff out from this tutorial, but I recall it looking different in the playground, or maybe in the learning section.
http://itp.nyu.edu/physcomp/Labs/ToneOutput

encryptor:
Now I know middle C is 440Hz (which i take is the frequency measured in Hz).

No, concert pitch A (or A4) is 440Hz, Middle C (or C4) is 261.626Hz.

At the site http://www.harpsatsang.com/harp_design/data/frequencies.html what would I chose for Ab or Bb? where do i find Tone.h because it's not under import library? i see playing a melody is a combination of using the melody[] and duration[]. Hasn't someone out there already figured out the durations i need to use? thx XD

crossroads - i tried the melody. it has a nice cell phone melody.

also I see what C mid real value is now.

I also tried, http://itp.nyu.edu/physcomp/Labs/ToneOutput
and at step 6.? Play Tones I'm not getting my speaker to play anything. I definitely have it wired correctly and could read min and max in step 5 using the photocells. what gives? I got a0 reading the value from photocells and digital pin 8 outputing power to the speaker. still no sound in dark or light. even when pressing reset. any ideas?

Nope. I have mine going to a MOSFET driving a speaker, good & loud!

At the site http://www.harpsatsang.com/harp_design/data/frequencies.html what would I chose for Ab or Bb?

For the flats, take the sharp from the note below, so Ab becomes G#.