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. :.
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!
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(){}
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
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?