Add documentation to music.c and minor fix to MLDY_PAUSE

This commit is contained in:
Thammi 2013-08-30 17:31:18 +02:00
parent 46d907c172
commit 68e429badb

View File

@ -12,15 +12,20 @@ static void tune(void) {
void set_note(uint16_t note, uint8_t octave) {
if(note != NOTE_PAUSE) {
// bring buzzer to a state where inverting it creates sound
buzzer_up();
// start timer with doubled frequency of tone we want to play
start_timer(PRESCALE_8, note >> octave, tune);
} else {
// do nothing when paused
stop_note();
}
}
void stop_note(void) {
// turn buzzer off to save energy
buzzer_off();
// we do not need the timer anymore
stop_timer();
}
@ -32,20 +37,25 @@ void play_melody(uint16_t notes[], size_t len, uint8_t octave, int speed) {
for(i = 0; i < len; ++i) {
if(notes[i] == MLDY_PAUSE) {
// user defined pause
++i;
wait_ms(notes[i] * 4 / length);
wait_ms(notes[i]);
} else if(notes[i] == MLDY_LENGTH) {
// sets length for next tone
++i;
length = notes[i];
} else {
// play note
set_note(notes[i], octave);
test_stop_app();
wait_ms(speed * 4 / length);
// pause after note
stop_note();
test_stop_app();
wait_ms(pause);
// reset length for next note
length = 4;
}
}