Pages: 1 [2]   Go Down
Author Topic: Error(s) preventing return to loop when code added  (Read 646 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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:
int noteDuration = 1000/noteDurationArray[thisNote];
tone(10, melodyArray[thisNote],noteDuration);

Substituted with functional variables:
Code:
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:
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?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
break
command if the denominator is 0. Solved...
Logged

East Anglia (UK)
Online Online
Faraday Member
**
Karma: 114
Posts: 4261
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Even better, add
Code:
break;
Logged

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

Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

don't worry, I worked that out fine.
Logged

Pages: 1 [2]   Go Up
Jump to: