Pages: [1]   Go Down
Author Topic: tone() function on sanguino  (Read 1727 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 25
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I'm not sure, if this topic fits in here. Maybe anybody can help me.
I was trieing to generate melodies with the tone() function. This was no problem with a duemilanove. On a Sanguino board the tone() function is not declared. See Code and error messages below. Can anybody find a reason?
thanks a lot!
obert

Code (from arduino.cc):
int melody[] = {
  NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4};

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

void setup() {
  // iterate over the notes of the melody:
  for (int 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.
    int noteDuration = 1000/noteDurations[thisNote];
    tone(8, melody[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;
    delay(pauseBetweenNotes);
    // stop the tone playing:
    noTone(smiley-cool;
  }
}

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

Error:
tone_nur_duemilanove_.cpp: In function 'void setup()':
tone_nur_duemilanove_:122: error: 'tone' was not declared in this scope
tone_nur_duemilanove_:129: error: 'noTone' was not declared in this scope
Logged

Portugal
Offline Offline
God Member
*****
Karma: 6
Posts: 962
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What is your Arduino IDE version?
Have you put this in the first line of your sketch outsid of any function?
 #include "pitches.h"
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 25
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,
I have tried it in version 0018 and 0022.
Yes, I have pitches.h included. As I wrote before, same code worked on the duemilanove but not on the sanguino.
Logged

Portugal
Offline Offline
God Member
*****
Karma: 6
Posts: 962
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So, it compiles if you select duemilanove but not sanguino?
Logged

Pages: [1]   Go Up
Jump to: