Home \ Help \ Search \ Login RSS

Welcome, Guest. Please Login

This forum is now READ-ONLY! Please visit http://forum.wiring.co/ for the new forum.

Wiring ForumSuggestionsWebsite,  Reference,  Example Suggestions › Pitches.h

Page Index Toggle Pages: 1
Pitches.h (Read 20022 times)
01/19/11 at 17:58:59

Vaccumdiode2   Offline
Full Member
chicago, IL USA

Posts: 120
***
 
Hello,
           I am adding sound to my Wiring christmas star.  The pitches.h has no information.  Which notes are there it?  are flats and sharps in it? 
           I have some charts I made so I could play all eight octives with flats and sharps.

          Any help or hints would be greatly apprecated.

Thank you,

Vaccumdiode 2
 
IP Logged
 
Reply #1 - 01/19/11 at 23:11:43

bhagman   Offline
YaBB Administrator
Toronto, Ontario, Canada

Posts: 20
*****
 
The pitches.h file found in the examples has a range of:

B0 -> D#8

These are just constants for the frequencies of each of the notes.  Sharps and flats are indicated with "S" in the note name (e.g. C#4 = CS4).

For example, to play a 4th octave C# on pin 8 for 200 milliseconds, you could use:

tone(8, NOTE_CS4, 200);

You don't have to use the pitches.h file.  If you have another way of getting the frequencies for notes that you're comfortable with, you should use that.

b
 
IP Logged
 
Reply #2 - 01/20/11 at 15:42:46

Vaccumdiode2   Offline
Full Member
chicago, IL USA

Posts: 120
***
 
B,
         That's a great little Library.  I'll be using it. 

       Thank you
Vaccumdiode2
 
IP Logged
 
Reply #3 - 01/21/11 at 18:18:16

Vaccumdiode2   Offline
Full Member
chicago, IL USA

Posts: 120
***
 
Hello,
         Where is the pitches.h.  It fail to be found by wiring 27.  I look around the wiring web site and couldn't find it. 

Thank you,
Vaccumdiode2
 
IP Logged
 
Reply #4 - 01/22/11 at 07:04:59

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
The file comes with the application, launch Wiring, and go to menu File -> Examples -> Basics -> 2.Digital Output -> toneMelody, it loads a sketch which has the file you mentioned, there other sketches providing that file as well.
 
IP Logged
 
Reply #5 - 03/14/11 at 12:23:37

Vaccumdiode2   Offline
Full Member
chicago, IL USA

Posts: 120
***
 
Hello,

           The new issue I have is that the tone function does not work correctly.  It plays the same tone, no matter what freq you give it.   I took the melody and liquidcrystal example and made a nice little test program.  I have a 4 row LCD and I Put up the 4 variables and watch them change.  I added Tempo.  They change and the tune plays but with the same tone.

I thought that the pitches.h was the problem so I change all the notes to Frequencies.  The pitches.h was an attached tab in the example sketch and the following sketch.

GRYMG4_001

Vaccumdiode2 Mar 12 2011

Code (C++):
#include "pitches.h"
#include <LiquidCrystal.h>

// creates a LiquidDisplay object with R/S, R/W and E on pins 8,9,10
// and data pins on port 2
LiquidCrystal myDisplay = LiquidCrystal(8,9,10,2);

//Tempo is the ms duration of a whole note dertermined by the Beats
// Per Minute BPM

int Tempo=1000;

// notes in the melody:
int freq[] = {
    659, 659, 988, 988, 880, 784, 698, 659, 587, 880, 659, 698, 784, 880
};

// note durations: 1=whole, 2=half, 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
  4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2
};

// noteDot: 1=no Dot, 1.5=Dot
int noteDot[] = {
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.5
};

void setup() {
  }
void loop() {
 
  // iterate over the notes of the melody:
  for (int thisNote = 0; thisNote < 14; thisNote++) {


    // to calculate the note duration, take one second
    // divided by the note type.
    //e.g. quarter note = Tempo /4, eighth note = tempo/8, etc.
    int noteDuration = Tempo/noteDurations[thisNote]*noteDot[thisNote];
    tone(7, freq[thisNote],noteDuration);

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.30;
   
    myDisplay.clear();
  myDisplay.home();
  myDisplay.print("thisNote a is: ");
  myDisplay.setCursor(16, 0);
  myDisplay.print(thisNote);
 
  myDisplay.setCursor(0, 1);
  myDisplay.print("Freq a is: ");
  myDisplay.setCursor(16, 1);
  myDisplay.print(feq[thisNote]);
   
  myDisplay.setCursor(0, 2);
  myDisplay.print("Duration a is: ");
  myDisplay.setCursor(16, 2);
  myDisplay.print(noteDuration);
   
  myDisplay.setCursor(0, 3);
  myDisplay.print("Between a is: ");
  myDisplay.setCursor(16, 3);
  myDisplay.print(pauseBetweenNotes); 
    delay(pauseBetweenNotes);
  }
} 



Thank you,
Vaccumdiode2 Undecided
« Last Edit: 03/15/11 at 02:28:01 by bhagman »  
IP Logged
 
Reply #6 - 03/15/11 at 04:57:47

bhagman   Offline
YaBB Administrator
Toronto, Ontario, Canada

Posts: 20
*****
 
Hiya!

What version of the IDE are you using?  I tested your code on 0027 and it is working (except for a typo in the code you posted - feq/freq - and I sent output to Serial instead of the LCD).

b
 
IP Logged
 
Reply #7 - 03/22/11 at 15:29:07

Vaccumdiode2   Offline
Full Member
chicago, IL USA

Posts: 120
***
 
B,
     I've been a little sheepish about serial outputs.  Could you post you code so I could try it. 
     I wonder why it is always the same tone for me.  I am using 0027. 
     How did it sound?  I took "God Bless Ye Merry Gentmen"  I've been teaching myself how to read music.  How did I do on my first atempt?

Thank you,

Vaccumdiode Smiley
 
IP Logged
 
Reply #8 - 03/29/11 at 01:44:08

bhagman   Offline
YaBB Administrator
Toronto, Ontario, Canada

Posts: 20
*****
 
Sorry for taking so long.

Code (C++):
//#include "pitches.h"
//#include <LiquidCrystal.h>

// creates a LiquidDisplay object with R/S, R/W and E on pins 8,9,10
// and data pins on port 2
//LiquidCrystal myDisplay = LiquidCrystal(8,9,10,2);

#define myDisplay Serial

//Tempo is the ms duration of a whole note dertermined by the Beats
// Per Minute BPM

int Tempo=1000;

// notes in the melody:
int freq[] = {
    659, 659, 988, 988, 880, 784, 698, 659, 587, 880, 659, 698, 784, 880
};

// note durations: 1=whole, 2=half, 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
  4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2
};

// noteDot: 1=no Dot, 1.5=Dot
int noteDot[] = {
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.5
};

void setup() {
  Serial.begin(9600);
  }
void loop() {

  // iterate over the notes of the melody:
  for (int thisNote = 0; thisNote < 14; thisNote++) {


    // to calculate the note duration, take one second
    // divided by the note type.
    //e.g. quarter note = Tempo /4, eighth note = tempo/8, etc.
    int noteDuration = Tempo/noteDurations[thisNote]*noteDot[thisNote];
    tone(27, freq[thisNote],noteDuration);

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.30;
   
//    myDisplay.clear();
//  myDisplay.home();
  myDisplay.println("thisNote a is: ");
//  myDisplay.setCursor(16, 0);
  myDisplay.println(thisNote);

//  myDisplay.setCursor(0, 1);
  myDisplay.println("Freq a is: ");
//  myDisplay.setCursor(16, 1);
  myDisplay.println(freq[thisNote]);
   
//  myDisplay.setCursor(0, 2);
  myDisplay.println("Duration a is: ");
//  myDisplay.setCursor(16, 2);
  myDisplay.println(noteDuration);
   
//  myDisplay.setCursor(0, 3);
  myDisplay.println("Between a is: ");
//  myDisplay.setCursor(16, 3);
  myDisplay.println(pauseBetweenNotes);
    delay(pauseBetweenNotes);
 
  myDisplay.println();
  }
 
  myDisplay.println("Done");
  for (;;);
}

 



Try that.

b
 
IP Logged
 
Reply #9 - 03/30/11 at 01:11:05

Vaccumdiode2   Offline
Full Member
chicago, IL USA

Posts: 120
***
 
B,
      Thank you.  I'll See if I get different tone now and see how the serial works.

Vaccumdiode Smiley
 
IP Logged
 
Page Index Toggle Pages: 1