Repeating a Void?

I was using the script on the link below and was wondering how I could make the song in the void repeat itself constantly or for a set number of times.

Any advice would be greatly appreciated
Alan

First find a void.

for(byte x=0; x <forAsetNumberofTimes; x++)
{
//Play your song
}

Post your code here if you want help.

I suspect that what you are calling a void is what C/C++ programmers call a function. But without seeing your code I can't be sure.

...R

#define NOTE_B0  31
#define NOTE_C1  33
#define NOTE_CS1 35
#define NOTE_D1  37
#define NOTE_DS1 39
#define NOTE_E1  41
#define NOTE_F1  44
#define NOTE_FS1 46
#define NOTE_G1  49
#define NOTE_GS1 52
#define NOTE_A1  55
#define NOTE_AS1 58
#define NOTE_B1  62
#define NOTE_C2  65
#define NOTE_CS2 69
#define NOTE_D2  73
#define NOTE_DS2 78
#define NOTE_E2  82
#define NOTE_F2  87
#define NOTE_FS2 93
#define NOTE_G2  98
#define NOTE_GS2 104
#define NOTE_A2  110
#define NOTE_AS2 117
#define NOTE_B2  123
#define NOTE_C3  131
#define NOTE_CS3 139
#define NOTE_D3  147
#define NOTE_DS3 156
#define NOTE_E3  165
#define NOTE_F3  175
#define NOTE_FS3 185
#define NOTE_G3  196
#define NOTE_GS3 208
#define NOTE_A3  220
#define NOTE_AS3 233
#define NOTE_B3  247
#define NOTE_C4  262
#define NOTE_CS4 277
#define NOTE_D4  294
#define NOTE_DS4 311
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_FS4 370
#define NOTE_G4  392
#define NOTE_GS4 415
#define NOTE_A4  440
#define NOTE_AS4 466
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_CS5 554
#define NOTE_D5  587
#define NOTE_DS5 622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5 740
#define NOTE_G5  784
#define NOTE_GS5 831
#define NOTE_A5  880
#define NOTE_AS5 932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6 1109
#define NOTE_D6  1175
#define NOTE_DS6 1245
#define NOTE_E6  1319
#define NOTE_F6  1397
#define NOTE_FS6 1480
#define NOTE_G6  1568
#define NOTE_GS6 1661
#define NOTE_A6  1760
#define NOTE_AS6 1865
#define NOTE_B6  1976
#define NOTE_C7  2093
#define NOTE_CS7 2217
#define NOTE_D7  2349
#define NOTE_DS7 2489
#define NOTE_E7  2637
#define NOTE_F7  2794
#define NOTE_FS7 2960
#define NOTE_G7  3136
#define NOTE_GS7 3322
#define NOTE_A7  3520
#define NOTE_AS7 3729
#define NOTE_B7  3951
#define NOTE_C8  4186
#define NOTE_CS8 4435
#define NOTE_D8  4699
#define NOTE_DS8 4978

#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,8,7,6,5);
const int LCDswitchPin = 3;
int LCDswitchState = 0;
int prevLCDswitchState = 0;
int LCDswitchCounter = 0;
int notes[] = {
  262,294,330,349,392,440,494};

void setup(){
  Serial.begin(9600);
  lcd.begin(16,2);
  pinMode(LCDswitchPin, INPUT);
}

void loop(){
  LCDswitchState = digitalRead(LCDswitchPin);
  int keyVal = analogRead(A0);
  Serial.println(keyVal);
  lcd.noDisplay();
  if(LCDswitchState == HIGH){
    lcd.display();
    lcd.clear();
    LCDstart();
  }
  if(keyVal >= 1022 && keyVal <= 1024){
    tone(2,notes[0]);
  }
  else if(keyVal >= 1000 && keyVal <= 1004){
    tone(2, notes[1]);
  }
  else if(keyVal >= 510 && keyVal <= 515){
    tone(2, notes[2]);
  }
  else if(keyVal >= 5 && keyVal <= 10){
    tone(2, notes[3]);
  }
  else if(keyVal >= 929 && keyVal <= 933){
    tone(2, notes[4]);
  }
  else if(keyVal >= 694 && keyVal <= 700){
    tone(2, notes[5]);
  }
  else if(keyVal >= 965 && keyVal <= 976){
    tone(2, notes[6]);
  }
  else{
    noTone(2);
  }
}

void LCDstart(){
  int keyVal = analogRead(A0);
  LCDswitchState = digitalRead(LCDswitchPin);
  while(LCDswitchState == LOW){
    LCDswitchState = digitalRead(LCDswitchPin);
    if(LCDswitchState == HIGH){
      LCDswitchCounter++;
      Serial.print("number of button pushes:");
      Serial.println(LCDswitchCounter);
      delay(300);
      Song1title();
      lcd.clear();
      break;
    }
    else{
      LCDswitchCounter = 0;
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Which Song Would");
      lcd.setCursor(0,1);
      lcd.print("You Like To Play");
      delay(50);
    }
  }
}

void Song1title(){
  int keyVal = analogRead(A0);
  LCDswitchState = digitalRead(LCDswitchPin);
  while(LCDswitchState == LOW){
    LCDswitchState = digitalRead(LCDswitchPin);
    if(LCDswitchState == HIGH){
      LCDswitchCounter++;
      Serial.print("number of button pushes:");
      Serial.println(LCDswitchCounter);
      delay(300);
      Song2title();
      lcd.clear();
      break;
    }
    else{
      int keyVal = analogRead(A0);
      Serial.println(keyVal);
      if(keyVal >= 2){
        Song1();
        break;
      }
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Super Mario Bros");
      lcd.setCursor(0,1);
      lcd.print("   Theme Song");
      delay(50);
    }
  }
}
void Song2title(){
  int keyVal = analogRead(A0);
  LCDswitchState = digitalRead(LCDswitchPin);
  while(LCDswitchState == LOW){
    LCDswitchState = digitalRead(LCDswitchPin);
    if(LCDswitchState == HIGH){
      LCDswitchCounter++;
      Serial.print("number of button pushes:");
      Serial.println(LCDswitchCounter);
      delay(300);
      Song3title();
      lcd.clear();
      break;
    }
    else{
      int keyVal = analogRead(A0);
      Serial.println(keyVal);
      if(keyVal >= 2){
        Song2();
        break;
      }
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Super Mario Bros");
      lcd.setCursor(0,1);
      lcd.print("   Underworld");
        delay(50);
    }
  }
}
void Song3title(){
  int keyVal = analogRead(A0);
  LCDswitchState = digitalRead(LCDswitchPin);
  while(LCDswitchState == LOW){
    LCDswitchState = digitalRead(LCDswitchPin);
    if(LCDswitchState == HIGH){
      LCDswitchCounter++;
      Serial.print("number of button pushes: ");
      Serial.println(LCDswitchCounter);
      delay(300);
      Song4title();
      lcd.clear();
      break;
    }
    else{
      int keyVal = analogRead(A0);
      Serial.println(keyVal);
      if(keyVal >= 2){
        Song3();
        break;
      }
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("The Hall of the");
      lcd.setCursor(0, 1);
      lcd.print("Mountain King");
      delay(50);
    }
  }
}
void Song4title(){
  int keyVal = analogRead(A0);
  LCDswitchState = digitalRead(LCDswitchPin);
  while(LCDswitchState == LOW){
    LCDswitchState = digitalRead(LCDswitchPin);
    if(LCDswitchState == HIGH){
      LCDswitchCounter++;
      Serial.print("number of button pushes: ");
      Serial.println(LCDswitchCounter);
      delay(300);
      Song5title();
      lcd.clear();
      break;
    }
    else{
      int keyVal = analogRead(A0);
      Serial.println(keyVal);
      if(keyVal >= 2){
        Song4();
        break;
      }
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Twinkle Twinkle");
      lcd.setCursor(0, 1);
      lcd.print("  Little Star");
      delay(50);
    }
  }
}
void Song5title(){
  int keyVal = analogRead(A0);
  LCDswitchState = digitalRead(LCDswitchPin);
  while(LCDswitchState == LOW){
    LCDswitchState = digitalRead(LCDswitchPin);
    if(LCDswitchState == HIGH){
      LCDswitchCounter=0;
      Serial.print("number of button pushes: ");
      Serial.println(LCDswitchCounter);
      delay(300);
      lcd.clear();
      break;
    }
    else{
      int keyVal = analogRead(A0);
      Serial.println(keyVal);
      if(keyVal >= 2){
        Song5();
        break;
      }
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("   Fur Elise");
      delay(50);
    }
  }
}
void Song1(){
  lcd.clear();
  int melody[] = {
    NOTE_E7, NOTE_E7, 0, NOTE_E7,
    0, NOTE_C7, NOTE_E7, 0,
    NOTE_G7, 0, 0,  0,
    NOTE_G6, 0, 0, 0,

    NOTE_C7, 0, 0, NOTE_G6,
    0, 0, NOTE_E6, 0,
    0, NOTE_A6, 0, NOTE_B6,
    0, NOTE_AS6, NOTE_A6, 0,

    NOTE_G6, NOTE_E7, NOTE_G7,
    NOTE_A7, 0, NOTE_F7, NOTE_G7,
    0, NOTE_E7, 0, NOTE_C7,
    NOTE_D7, NOTE_B6, 0, 0,

    NOTE_C7, 0, 0, NOTE_G6,
    0, 0, NOTE_E6, 0,
    0, NOTE_A6, 0, NOTE_B6,
    0, NOTE_AS6, NOTE_A6, 0,

    NOTE_G6, NOTE_E7, NOTE_G7,
    NOTE_A7, 0, NOTE_F7, NOTE_G7,
    0, NOTE_E7, 0, NOTE_C7,
    NOTE_D7, NOTE_B6, 0, 0
  };
  int noteDurations[] = {
    12, 12, 12, 12,
    12, 12, 12, 12,
    12, 12, 12, 12,
    12, 12, 12, 12,

    12, 12, 12, 12,
    12, 12, 12, 12,
    12, 12, 12, 12,
    12, 12, 12, 12,

    9, 9, 9,
    12, 12, 12, 12,
    12, 12, 12, 12,
    12, 12, 12, 12,

    12, 12, 12, 12,
    12, 12, 12, 12,
    12, 12, 12, 12,
    12, 12, 12, 12,

    9, 9, 9,
    12, 12, 12, 12,
    12, 12, 12, 12,
    12, 12, 12, 12,
  };

  lcd.setCursor(1,0);
  lcd.print("Now playing...");
  lcd.setCursor(0,1);
  lcd.print("Mario Theme Song");

  int size = sizeof(melody) / sizeof(int);
  for(int thisNote = 0; thisNote < size; thisNote++){
    int noteDuration = 1000 / noteDurations[thisNote];
    tone(2, melody[thisNote], noteDuration);
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    tone(2, 0, noteDuration);
  }
  Song1title();
}

I didn't post the code for the other voids with the other 4 songs as i just repeat the same process with different songs.

I didn't post the code for the other voids

They are called functions they are not called voids. Others tried to hint gently at this but you don't seem to get it. The word void means that the function definition that follows does not return any value. So please don't call functions voids, it makes you look foolish and makes us cringe.

Reply #1 gave you the answer about how to repeat a function. Please ask what you did not understand about this answer rather than ignoring it.

Sorry Grumpy_Mike I'll make sure to call them functions in the future. I am clearly new to programming so calling me an idiot isn't very helpful. The part I didn't understand was how to make it repeat infinitely rather than a set number of times. Thanks to LarryD and Robin2 for offering their advice.

alan15:
The part I didn't understand was how to make it repeat infinitely rather than a set number of times.

The function loop() repeats indefinitely. if you want your function to repeat indefinitely just call it from loop()

void loop() {
   myFunction();
}

...R

Ok thanks

alan15:
I am clearly new to programming so calling me an idiot isn't very helpful.

When did I ever call you an idiot?
I said by using the wrong word made you look foolish. This is not saying you are foolish, it is saying it makes you look it.