Pages: [1] 2   Go Down
Author Topic: Error(s) preventing return to loop when code added  (Read 490 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

Hello,

New to the Forum and Arduino so any help is much appreciated!
I'm writing a script which responds to a knock sequence from one peizo, it does a comparison of an existing array of sequence, and if there is a match, responds a tone sequence via a second peizo. My code works fine until I added an "error clause" when the wrong knock is detected. When that part of the code is commented out the script responds as it should, then returns to listening for another knock. When I un-comment the code and it is in the script it response with the correct tone but stops there and wont cycle back to the beginning!

Thanks for your patience.

The section of code in question is:

Code:
   Serial.println("*********Correct combination of notes!***********");
  Serial.println("    ");  
Serial.println("Reseting of arrays occuring.....");
    for(int i=0;i<maximumIntervals;i++){        //Reset temp array noteDurationArray
      noteDurationArray[i] = 0;
      melodyArray[i] = 0;      //Reset temp array for melody
      Serial.print(" noteDurationArray: ");
      Serial.print(noteDurationArray[i]);
      Serial.print("   melodyArray: ");
      Serial.println(melodyArray[i]);
  }
  Serial.println(responseNumber);  
  Serial.println("Transposition occuring.....");
    for(int i=0;i<maximumIntervals;i++){        //transponse stored response from array to noteDurationArray
      noteDurationArray[i] = noteDurations[responseNumber][i];
      melodyArray[i] = melody[responseNumber][i];
      Serial.print(" noteDurationArray: ");
      Serial.print(noteDurationArray[i]);
      Serial.print("   melodyArray: ");
      Serial.println(melodyArray[i]);
    }
      Serial.println("---------------------------Reached play melody part");
Serial.println(responseNumber);    
      // iterate over the notes of the melody:
               for (int thisNote = 0; thisNote < 8; thisNote++) {
                // to calculate the note duration, take one second
                // divided by the note type.
                //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
                    int noteDuration = 1000/noteDurationArray[thisNote];
                    tone(10, melodyArray[thisNote],noteDuration);
                          // to distinguish the notes, set a minimum time between them.
                          // the note's duration + 30% seems to work well:
                    int pauseBetweenNotes = noteDuration * 1.30;
                    delay(pauseBetweenNotes);
                          // stop the tone playing:
                    noTone(10);
              }
         digitalWrite(redLED, HIGH);
         delay(500);
         digitalWrite(redLED, LOW);
}

This has been doing my head in as I can't fix or work out the issue smiley-sad

(word limit exceeded with script so any suggestions where to post?)

* response_array_attempt__3_not_working_atm.ino (14.39 KB - downloaded 7 times.)
* pitches.h (1.96 KB - downloaded 7 times.)
« Last Edit: February 02, 2013, 12:28:59 pm by fanuch » Logged

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

It would be helpful to see the full code.
You can attach it to a post - look at Additional options bottom/left of the input box when posting a reply.
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

Thanks for letting me know, I've included my full code as an ".ino" and the sound tab i used for outputs.

 smiley
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46113
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Which Arduino are you trying to run this on? It looks to me like it takes more memory than a 328-based Arduino has.
Logged

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

Really? It was running fine with Serial inputs and all until I added the last bit which would complete my code  smiley-cry

Runnning an Uno.

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46113
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
It was running fine with Serial inputs and all until I added the last bit which would complete my code
"It was running just fine until I needed to use more SRAM. Then, I ran out, and it doesn't work anymore. Why not?"

I think we've discovered the answer to that question. Look at your arrays. Do the int arrays need to be int sized? Could they be byte sized, instead, and use half the memory?

You can use the F() macro to keep constant strings out of SRAM:
Serial.print(F("This doesn't end up in SRAM");
Logged

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

Changed the types to byte but it didn't help I'm afraid. I feel there is something in that section of code that is preventing the loop. Some kind of termination, though I can't see it no matter how hard I try and find it.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 239
Posts: 24371
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

And the F macro for the strings?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

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

gave me errors for every single one that I changed.

I don't know much admittedly but the code loops if I omit this chunk of code and the end. Thanks for your support by the way.

Code:
// iterate over the notes of the melody:
               for (int thisNote = 0; thisNote < 8; thisNote++) {
                // to calculate the note duration, take one second
                // divided by the note type.
                //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
                    int noteDuration = 1000/noteDurationArray[thisNote];
                    tone(10, melodyArray[thisNote],noteDuration);
                          // to distinguish the notes, set a minimum time between them.
                          // the note's duration + 30% seems to work well:
                    int pauseBetweenNotes = noteDuration * 1.30;
                    delay(pauseBetweenNotes);
                          // stop the tone playing:
                    noTone(10);
              }
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 239
Posts: 24371
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
gave me errors for every single one that I changed
, and I'm not going to show the errors or the code.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

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

Code:
initializer fails to determine size of '__c'

if that helps
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 239
Posts: 24371
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, I suppose that's a part of what I asked for.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

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

IDE didn't like it on some of the Serial.print involving variables, no more error code. Still trying to resolve it or find a way around it. If it is SRAM isn't there a way to reset it? It is outputting the correct responses it just stops after playing a short beep response.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 239
Posts: 24371
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
IDE didn't like it on some of the Serial.print involving variables
That's because the F macro leaves constants in program memory, but cannot put variables into program memory.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

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

Ahh, thanks for explaining that.
Logged

Pages: [1] 2   Go Up
Jump to: