Pages: [1]   Go Down
Author Topic: Problem with file "pitches.h" in tutorial sketch "Melody".  (Read 4922 times)
0 Members and 2 Guests are viewing this topic.
Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Recently I bought an Arduino Uno board (version 3). I am working with Arduino IDE 1.0.4. I am trying to execute the sketch "Melody" (http://arduino.cc/en/Tutorial/Tone). The sketch begins with the statement: #include "pitches.h". In this file "pitches.h" the frequencies of the musical notes are defined by #define statements. In the following program line the array "melody[]" is declared and initialised with some of the contstants defined in "pitches.h". Compiling the sketch results in a number of error messages saying that the compiler does not know these constants. Apparently the statement #include "pitches.h" doesn't work.

I have tried a number of things, but nothing worked:
- Located the file "pitches.h" in the same folder (named "Melody") as "melody.ino". This provides the IDE with a second tab "pitches.h", but didn't work either.
- Located the file "pitches.h" in the folder "libraries".
- Chanched the statement into #include <"pitches.h">
- Tried to change "pitches.h" into a proper library as described here http://arduino.cc/en/Hacking/LibraryTutorial. This is difficult because "pitches.h" has neither variables nor functions. I am not sure I did this the right way.

Hopefully any of you can help me?

Pim Veld.
Logged

0
Offline Offline
Sr. Member
****
Karma: 8
Posts: 291
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can make libraries/pitches/pitches.h

you can also copy and paste all of those constants at the beginning of your melody sketch. Make sure to delete the #include "pitches.h".

Logged

Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for your reaction.
I understand that I can circumvent the problem by copying the constants at the beginning of the melody sketch. But I should like to know what is wrong with the code in the tutorial-sketch (because I want to learn how this should be done). I tried putting the file pitches.h in a folder pitches in the libraries-folder, but that didn't work either.

Any other idea's?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 653
Posts: 50881
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I followed the directions on that page (copy the sketch, paste the sketch, create a new tab called pitches.h, copy the code, paste the code), and I got this "error" message:
Quote
Binary sketch size: 3,396 bytes (of a 30,720 byte maximum)
Logged

Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

To PaulS: That's not an error message, that is a normal message after a successful compilation. So, apparently you had no difficulties in making it work. Can you please tell me how you created an new tab, because I can't find the button indicated in the tutorial to make a new tab.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As far as I know, the line should be:

Code:
#include <pitches.h>

without any """""" 's Or am I misreading the problem?

EDIT: Btw might be an issue indeed that the 'library' only has an .h file. All libraries Ive worked with consisted of a map with at least .h and .cpp file....
« Last Edit: March 26, 2013, 07:56:30 am by jzuidema » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 653
Posts: 50881
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
That's not an error message, that is a normal message after a successful compilation.
That's why error was in quotes.

Quote
Can you please tell me how you created an new tab, because I can't find the button indicated in the tutorial to make a new tab.
Which version of the IDE are you using? On 1.0+, there is an icon on the right side of the dialog (on Windows, anyway) that looks like the one in the tutorial (an arrow pointing to the right) that is used to create a new tab.
Logged

Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks again for your responses!

To jzuidema:
Indeed, according to the "Reference" it should be #include <pitches.h> (without quotes around pitches.h). I think I tried that too, but I am not sure. I will try that again (but then I still wonder why the tutorial doesn't show it like that). And indeed, the .ccp file is missing. But the pitches.h file as shown in the tutorial is not a proper library at all and trying to make a .ccp file with it is not possible or too difficult for me (see my first post).

To PaulS:
As I stated, I use IDE version 1.0.4. I don't know what you mean by "dialog", but just above the window in which you type the statements of the program there are 5 buttons on the left side and 1 at the utmost right side. The first two utmost left buttons are round, the other 4 buttons are square. The buttons are (from left to right): Verify, Upload, New, Open, Save and Serial Monitor. So no button with a right arrow for New Tab.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 653
Posts: 50881
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
(but then I still wonder why the tutorial doesn't show it like that).
Because pitches.h belongs in the same directory as the sketch, so the double quotes are correct, not <>.

Quote
And indeed, the .ccp file is missing.
Because there is no code to put in it.

Quote
But the pitches.h file as shown in the tutorial is not a proper library at all
Exactly. Only you thought it might be.

Quote
As I stated, I use IDE version 1.0.4.
I just fired it up. Looks exactly like 1.0.3.

Quote
I don't know what you mean by "dialog",
What else would you call the window that pops up? In computer program parlance, that's a dialog.

Quote
but just above the window in which you type the statements of the program there are 5 buttons on the left side and 1 at the utmost right side.
On the top row, yes. There is also a tab where you enter the sketch, and on the same level as the tab, on the far right (just under the serial monitor icon) there is an icon with a downward triangle (the tutorial is showing an old icon). Click that icon.
Logged

Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

To Paul S:
Thank you for your efforts and patience, I do really appreciate it!

The explanation of the #include statement only talks about libraries (<library.h>) and not about the possibility to include a piece of program from a file in another tab ("file.h"). That's why I assumed it should be a library.
I know what a dialog window is, but a window for typing in program statements I would rather call an editing window than a "dialog". I know my description was childischly clear, but I am new to Arduino and didn't want to leave any doubts. When a program is called a "sketch" it could well be that other parts of the IDE have funny names as well.

I found the "arrow-down" button and the menu-item "New Tab"! It never occurred to me that this is a menu-button. Again I downloaded the text of pitches.h from the website and pasted it into the new tab. And now it works!!!!

Thank you all for helping me out. I learned a couple of useful things from this experience.!
Logged

Pages: [1]   Go Up
Jump to: