24 #if defined(ARDUINO) && ARDUINO >= 100
133 unsigned long duration = 0;
134 for (
unsigned int index = 0; index < size; ++index)
135 duration += (1000 / lengths[index]) * 13 / 10;
136 _loopCount = (int)(ms / duration);
151 loopsLeft = _loopCount;
203 this->lengths = lengths;
218 if ((millis() - startNote) >= duration) {
224 void Melody::nextNote()
227 if (loopsLeft != 0 && --loopsLeft <= 0) {
233 duration = 1000 / lengths[posn];
234 if (notes[posn] != NOTE_REST)
235 tone(_pin, notes[posn], duration);
237 duration = duration * 13 / 10;
238 startNote = millis();
void setMelody(const int *notes, const uint8_t *lengths, unsigned int size)
Sets the melody to the size elements of notes and lengths.
void stop()
Stops playing the melody.
void run()
Runs the melody control loop.
void playOnce()
Plays the melody once and then stops.
Melody(uint8_t pin)
Constructs a new melody playing object for pin.
void setLoopDuration(unsigned long ms)
Sets the maximum number of loops to last no longer than ms milliseconds.
void play()
Starts playing the melody, or restarts it if already playing.