Go Down

Topic: Error(s) preventing return to loop when code added (Read 735 times) previous topic - next topic

fanuch

I substituted my multi array with a single array and the code works,

These are the variables and the specific lines of code.

Declaired variables:
Code: [Select]
int melodyArray[10] = { 0 };            //Temp array for melody for music playback
int noteDurationArray[10] = { 0 };      //Temp array for duration of notes for music playback


Respective line of code:
Code: [Select]
int noteDuration = 1000/noteDurationArray[thisNote];
tone(10, melodyArray[thisNote],noteDuration);


Substituted with functional variables:
Code: [Select]
int melody[] = {
  NOTE_F4, NOTE_E4, NOTE_D4, NOTE_CS4, NOTE_AS3, NOTE_C4, NOTE_D4, NOTE_D4};
int noteDurations[] = {  4, 4, 4, 4, 4, 4, 3, 2, 4 };


Substituted with functional lines of code:
Code: [Select]
int noteDuration = 1000/noteDurations[thisNote];
tone(10, melody[thisNote],noteDuration);


That's as narrow down to the root of the problem I can ascertain.
Any thing out of the ordinary or problematic?

fanuch

Anyone who was following or cares, the problem was that it was dividing 1000 by 0 which caused it to go crazy and paradoxical. Added a simple
Code: [Select]
break command if the denominator is 0. Solved...

UKHeliBob

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

fanuch


Go Up