How to only run this once?

Hi guys, and thank you for your time.
I’ve got really stuck trying to run ''GameOfThrones" just once on the program you’ll find below.

It runs once at the beggining, but then when I try to do something in the Bluetooth (this is the program of a BT-controlled boat) it just runs again, and it’s very annoying.
Please, if anyone knows how could I fix this, I’d really appreciate your help.
Here is the code, and thank you very much!


#include <SoftwareSerial.h>
#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

// Altavoz
int speakerPin = 9;

SoftwareSerial BT(2, 3);

// Motor A
int ENA = 6;
int IN1 = 13;
int IN2 = 12;

// Motor B
int ENB = 5;
int IN3 = 11;
int IN4 = 10;

//MOTOR TRASERO

int ENC = 8 ;
int IN5 = 7 ;
int IN6 = 4 ;

int vel = 180;
int velC = 200;

void GameOfThrones() {
for(int i=0; i<4; i++) {
tone(speakerPin, NOTE_G4);

delay(500);
noTone(speakerPin);

tone(speakerPin, NOTE_C4);

delay(500);
noTone(speakerPin);

tone(speakerPin, NOTE_DS4);

delay(250);
noTone(speakerPin);

tone(speakerPin, NOTE_F4);

delay(250);
noTone(speakerPin);

}

for(int i=0; i<4; i++){
tone(speakerPin, NOTE_G4);

delay(500);
noTone(speakerPin);

tone(speakerPin, NOTE_C4);

delay(500);
noTone(speakerPin);

tone(speakerPin, NOTE_E4);

delay(250);
noTone(speakerPin);

tone(speakerPin, NOTE_F4);

delay(250);
noTone(speakerPin);

}

}

void setup()
{
BT.begin(9600) ;
// Declaramos todos los pines como salidas
pinMode (ENA, OUTPUT);
pinMode (ENB, OUTPUT);
// pinMode(ENC, OUTPUT);
pinMode (IN1, OUTPUT);
pinMode (IN2, OUTPUT);
pinMode (IN3, OUTPUT);
pinMode (IN4, OUTPUT);
pinMode(IN5, OUTPUT);
pinMode(IN6, OUTPUT);

pinMode(speakerPin, OUTPUT);
GameOfThrones();
}

void loop()
{

if (BT.available()){
switch (BT.read())
{
case ‘F’:
Adelante();
break;
case ‘B’:
Atras();
break;
case ‘R’:
Derecha();
break;
case ‘L’:
Izquierda();
break;
case ‘S’:
Parar();
break;
}
}
}

void Adelante ()
{
//Direccion motor A
digitalWrite (IN1, LOW);
digitalWrite (IN2, HIGH);
analogWrite (ENA, vel); //Velocidad motor A

//Direccion motor B
digitalWrite (IN3, LOW);
digitalWrite (IN4, HIGH);
analogWrite (ENB, vel); //Velocidad motor B

//Direccion motor C
digitalWrite(IN5, LOW);
digitalWrite(IN6, HIGH);
analogWrite(ENC, vel); //Velocidad motor C
}

void Atras ()
{
//Direccion motor A
digitalWrite (IN1, HIGH);
digitalWrite (IN2, LOW);
analogWrite (ENA, vel); //Velocidad motor A
//Direccion motor B
digitalWrite (IN3, HIGH);
digitalWrite (IN4, LOW);
analogWrite (ENB, vel); //Velocidad motor B
//Direccion motor C
digitalWrite(IN5, HIGH);
digitalWrite(IN6, LOW);
analogWrite(ENC, vel); //Velocidad motor C
}

void Derecha ()
{
//Direccion motor A
digitalWrite (IN1, LOW);
digitalWrite (IN2, HIGH);
analogWrite (ENA, vel); //Velocidad motor A
//Direccion motor B
digitalWrite (IN3, HIGH);
digitalWrite (IN4, LOW);
analogWrite (ENB, vel); //Velocidad motor A
}

void Izquierda ()
{
//Direccion motor A
digitalWrite (IN1, HIGH);
digitalWrite (IN2, LOW);
analogWrite (ENA, vel); //Velocidad motor A
//Direccion motor B
digitalWrite (IN3, LOW);
digitalWrite (IN4, HIGH);
analogWrite (ENB, vel); //Velocidad motor A
}

void Parar ()
{
//Direccion motor A
digitalWrite (IN1, LOW);
digitalWrite (IN2, LOW);
analogWrite (ENA, 0); //Velocidad motor A

//Direccion motor B
digitalWrite (IN3, LOW);
digitalWrite (IN4, LOW);
analogWrite (ENB, 0); //Velocidad motor A

//Direccion motor C
digitalWrite(IN5, LOW);
digitalWrite(IN6, LOW);
analogWrite(ENC, 0); //Velocidad motor C
}

If you're seeing that function again then it would appear that your board is resetting. How are you driving these motors? You're not trying to power them off the Arduino are you?

First use the code tags, as it appears u are new here so READ this https://forum.arduino.cc/index.php?topic=149014.0 .
As for the code it appears u have something resetting your board and going through the void setup() again something like opening the serial monitor.

Ok, saber-h. Yes, I'm indeed new here and I've read that you meant. Thank you.
I'm driving those motors thanks to the L298N (I've got two of them because I'm managing 3 motors)
I don't have any kind of explanation to why the board is resetting...

Where do the motors get their power?

9V cells

Does the Arduino get power from the same? You don't mean one of those square looking batteries that goes in the smoke detector do you? Those are no good for motors. Probably your issue is the motors are sagging the voltage to the point that the Arduino loses power. Get a handful of AA batteries and see if that doesn't work better.