void melodie(){ // Play melody 1- number mel from external eeprom - new if (snd > 0){ // Melody not stopped ofset = (snd-1) * ((length*4) +15); // Offset = 0*50*2= 0, 1*50*2 = 100 integers! *2 -> *4 int ext_ee_adr = EXT_EE_MELODY_R+1 + ofset; // Address base + offset - ignore first byte which is the data-type - moved to here 26-09-2025 tempo=read_ext_eeprom(ext_ee_adr + 14); // Melody tempo starts at address +14 int wholenote = (60000 * 4) / tempo; // Calculate note (tempo is integer) int divider = 0, noteDuration = 0; // Clear divider and note duration divider=read_integer(ext_ee_adr+15+thisNote+2); // note: pitch: byte byte length: byte byte skip first eeprom address -> +2 if (divider > 0) { // regular note, just proceed noteDuration = (wholenote) / divider; } // Calculate regular note duration else if (divider < 0) { // dotted notes are represented with negative durations!! noteDuration = (wholenote) / abs(divider);// Calculate dotted note duration noteDuration *= 1.5; } // increases the duration in half for dotted notes note = read_integer(ext_ee_adr+15+thisNote);// note globaly defined! //tone(BUZZER, note, noteDuration * 0.9); // Play note for tone() - play only 90% of the duration, leaving 10% as a pause 23-09-2025 TimerFreeTone(BUZZER,note,noteDuration*0.6,10);// Play note for TimerFreeTone 0.9 is too long -> 0.45 too short ->0.65 too long //NewTone(BUZZER,note,noteDuration*90); // Play note for NewTone() //delay(noteDuration); // Pause for tone() was / 2 delay(noteDuration/8); // Pause for TimerFreeTone() /2 is to long -> /4 too long -> 8 //delay(noteDuration/25); // Pause for NewTone() if (thisNote < (length*4)-2) // Index within limits? {thisNote=thisNote+4;} // Next note = thisNote +2 old - new = +4 else {thisNote= 0; snd = 0; } // Rewind to first adress, end music - noTone moved to central tone off //else {thisNote= 0; snd = 0; noTone(BUZZER);}// Rewind to first adress, end music - noTone moved to central tone off } }