Go Down

Topic: tone() function on sanguino (Read 2138 times)previous topic - next topic

Ardukopter

Apr 30, 2011, 09:21 pm
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(;
}
}

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

Senso

#1
May 01, 2011, 03:59 am
What is your Arduino IDE version?
Have you put this in the first line of your sketch outsid of any function?
#include "pitches.h"

Ardukopter

#2
May 01, 2011, 10:11 am
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.

Senso

#3
May 02, 2011, 02:16 am
So, it compiles if you select duemilanove but not sanguino?

Go Up

Please enter a valid email to subscribe