Trouble modifying "Time Test" sketch.

With the enclosed sketch, “Random Color” is not very random at all, the fluctuations are TOO extreme.
I would like to be able to insert a pre-determined sequence of the 3 Leds. I have tried "deleting ", Random Color and incorporating my sequence instead. (no luck)
I understand each subsequent “new test”(new sequence) would have to carry on again and again, until eventually I got to the end of the loop, and it could all start over again
Is it possible to achieve what I would like to happen.
Any help would be much appreciated . Chaso.

//After Dinner Reaction Time tester - created by Bertus52x11
//Used a RGB LED with a common Anode (3 Cathodes: R, G, B).
//Therefore, some “digitalwrite” commands may seem ackward: HIGH=off and LOW=on.

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11,10, 5, 4, 3, 2);

int backLight = 13;

int LEDR = 6; // Red Led pin 6
int LEDB = 7; // Blue Led pin 7
int LEDGr = 8; // Green Led pin 6
int Button=1;
int COLOR; // variable Color
int Beep;
int PSE; // variable pause
int TME; // Time
int RTME=0; // Reaction Time

void setup()
{
pinMode(backLight,OUTPUT);
digitalWrite(backLight,HIGH);
lcd.begin(16, 2);
pinMode(LEDR, OUTPUT);
pinMode(LEDB, OUTPUT);
pinMode(LEDGr, OUTPUT);
pinMode(Button, INPUT);
digitalWrite(LEDR, HIGH); // All lights are switched “on”.
digitalWrite(LEDB, HIGH);
digitalWrite(LEDGr, HIGH);
}

void loop()
{
lcd.clear(); // Clear screen.
lcd.print(“Hold Button to”);
lcd.setCursor(0,1); // move to second line.
lcd.print(“start.”);
while (digitalRead(Button)==LOW) // The test does not start until the button is pushed (and held down).
{tone(13,1200,30);
delay(1400);
noTone(13);
}

lcd.clear();
digitalWrite(LEDR, LOW); // switch off the "start"light.
digitalWrite(LEDB, LOW);
digitalWrite(LEDGr, LOW);
randomSeed(analogRead(0)); //Random noise from pin 0
COLOR = random(1,4); // Generate a random color.
PSE=random(500,1200); // Select a random pause between the lights (to increase the surprise effect).

while (COLOR!=1 && digitalRead(Button)==HIGH)// This loop is repeated while color is Green or Blue AND button is held down.
{
digitalWrite(LEDGr, LOW);
digitalWrite(LEDB, LOW);
delay(PSE);
randomSeed(analogRead(0));
Beep=random(1,4); // Select whether to beep or not (1 in 3 times).
PSE=random(750,1200); // Select a random pause between the lights (to increase the surprise effect).

if (Beep==1)
{tone(13,1600,350);
delay(750);
noTone(13);}
if (COLOR == 2)
{digitalWrite(LEDGr, HIGH);}
if (COLOR == 3)
{digitalWrite(LEDB, HIGH);}
delay(PSE);
randomSeed(analogRead(0));
COLOR = random(1,4); // Select a random color.
}

if (COLOR == 1 && digitalRead(Button)==HIGH)// This loop is executed if the color is red.
{
digitalWrite(LEDGr, LOW);
digitalWrite(LEDB, LOW);
delay(PSE);
TME=millis(); // Time since this program has started (so Blue or Green loop included).
digitalWrite(LEDR, HIGH);

while (digitalRead(Button)==HIGH)// This loop runs untill you have released the button, hence the reaction time.
{delay(1);}
lcd.display();
RTME=millis()-TME; // Time since Led is Red, hence reaction time.
lcd.print(“Reaction Time:”);
lcd.setCursor(0,1);
lcd.print(RTME);
}

if (COLOR != 1) // This step is executed if the color is NOT red but the Push button was released (wrong action).
{
lcd.print(“Released too”);
lcd.setCursor(0,1); // move to second line.
lcd.print(“soon !!!”);
tone(13,3000,1500);
delay(500);
noTone(13);
}

while (digitalRead(Button)==LOW) // The test does not re-start until the button is pushed once.
{delay(10);}

digitalWrite(LEDR, HIGH); // Resets all lights to begin again.
digitalWrite(LEDB, HIGH);
digitalWrite(LEDGr, HIGH);
lcd.clear();
lcd.print(“Hold Button to”);
lcd.setCursor(0,1);
lcd.print(“start.”);
int Time=0;
delay(1000);
}

Can you post using code tags, rather then "copy for forum" please?

Read this before posting a programming question

[ 
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11,10, 5, 4, 3, 2);

int backLight = 13;

int LEDR = 6; // Red Led pin 6
int LEDB = 7; // Blue Led pin 7
int LEDGr = 8; // Green Led pin 6
int Button=1;
int COLOR; // variable Color
int Beep;
int PSE; // variable pause 
int TME; // Time
int RTME=0; // Reaction Time

void setup()
{
  pinMode(backLight,OUTPUT);
  digitalWrite(backLight,HIGH);
lcd.begin(16, 2); 
pinMode(LEDR, OUTPUT);
pinMode(LEDB, OUTPUT);
pinMode(LEDGr, OUTPUT);
pinMode(Button, INPUT);
digitalWrite(LEDR,  HIGH); // All lights are switched "on".
digitalWrite(LEDB,  HIGH);
digitalWrite(LEDGr,  HIGH);
}

void loop()
{
lcd.clear(); // Clear screen.
lcd.print("Hold Button to");
lcd.setCursor(0,1); // move to second line.
lcd.print("start.");
while (digitalRead(Button)==LOW) // The test does not start until the button is pushed (and held down).
{tone(13,1200,30);
delay(1400);
noTone(13);
}

lcd.clear();
digitalWrite(LEDR, LOW); // switch off the "start"light.
digitalWrite(LEDB, LOW);
digitalWrite(LEDGr, LOW);
randomSeed(analogRead(0)); //Random noise from pin 0
COLOR = random(1,4); // Generate a random color.
PSE=random(500,1200); // Select a random pause between the lights (to increase the surprise effect).


while (COLOR!=1 && digitalRead(Button)==HIGH)// This loop is repeated while color is Green or Blue AND button is held down.
{
digitalWrite(LEDGr,  LOW);
digitalWrite(LEDB,  LOW);
delay(PSE);
randomSeed(analogRead(0));
Beep=random(1,4); // Select whether to beep or not (1 in 3 times).
PSE=random(750,1200); // Select a random pause between the lights (to increase the surprise effect).

if (Beep==1)
{tone(13,1600,350);
delay(750);
noTone(13);}
if (COLOR == 2)
{digitalWrite(LEDGr, HIGH);}
if (COLOR == 3)
{digitalWrite(LEDB, HIGH);}
delay(PSE);
randomSeed(analogRead(0));
COLOR = random(1,4);  // Select a random color.
}


if (COLOR == 1 && digitalRead(Button)==HIGH)// This loop is executed if the color is red.
{
digitalWrite(LEDGr,   LOW);
digitalWrite(LEDB,  LOW);
delay(PSE);
TME=millis(); // Time since this program has started (so Blue or Green loop included).
digitalWrite(LEDR, HIGH);

while (digitalRead(Button)==HIGH)// This loop runs untill you have released the button, hence the reaction time.
{delay(1);}
lcd.display();
RTME=millis()-TME; // Time since Led is Red, hence reaction time.
lcd.print("Reaction Time:");
lcd.setCursor(0,1);
lcd.print(RTME);
}

if (COLOR != 1) // This step is executed if the color is NOT red but the Push button was released (wrong action). 
{
lcd.print("Released too");
lcd.setCursor(0,1); // move to second line.
lcd.print("soon !!!");
tone(13,3000,1500);
delay(500);
noTone(13);
}


while (digitalRead(Button)==LOW) // The test does not re-start until the button is pushed once.
{delay(10);}

digitalWrite(LEDR, HIGH); // Resets all lights to begin again.
digitalWrite(LEDB, HIGH);
digitalWrite(LEDGr, HIGH);
lcd.clear();
lcd.print("Hold Button to");
lcd.setCursor(0,1);
lcd.print("start.");
int Time=0;
delay(1000);
}

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11,10, 5, 4, 3, 2);

int backLight = 13;

int LEDR = 6; // Red Led pin 6
int LEDB = 7; // Blue Led pin 7
int LEDGr = 8; // Green Led pin 6
int Button=1;
int COLOR; // variable Color
int Beep;
int PSE; // variable pause 
int TME; // Time
int RTME=0; // Reaction Time

void setup()
{
  pinMode(backLight,OUTPUT);
  digitalWrite(backLight,HIGH);
lcd.begin(16, 2); 
pinMode(LEDR, OUTPUT);
pinMode(LEDB, OUTPUT);
pinMode(LEDGr, OUTPUT);
pinMode(Button, INPUT);
digitalWrite(LEDR,  HIGH); // All lights are switched "on".
digitalWrite(LEDB,  HIGH);
digitalWrite(LEDGr,  HIGH);
}

void loop()
{
lcd.clear(); // Clear screen.
lcd.print("Hold Button to");
lcd.setCursor(0,1); // move to second line.
lcd.print("start.");
while (digitalRead(Button)==LOW) // The test does not start until the button is pushed (and held down).
{tone(13,1200,30);
delay(1400);
noTone(13);
}

lcd.clear();
digitalWrite(LEDR, LOW); // switch off the "start"light.
digitalWrite(LEDB, LOW);
digitalWrite(LEDGr, LOW);
randomSeed(analogRead(0)); //Random noise from pin 0
COLOR = random(1,4); // Generate a random color.
PSE=random(500,1200); // Select a random pause between the lights (to increase the surprise effect).


while (COLOR!=1 && digitalRead(Button)==HIGH)// This loop is repeated while color is Green or Blue AND button is held down.
{
digitalWrite(LEDGr,  LOW);
digitalWrite(LEDB,  LOW);
delay(PSE);
randomSeed(analogRead(0));
Beep=random(1,4); // Select whether to beep or not (1 in 3 times).
PSE=random(750,1200); // Select a random pause between the lights (to increase the surprise effect).

if (Beep==1)
{tone(13,1600,350);
delay(750);
noTone(13);}
if (COLOR == 2)
{digitalWrite(LEDGr, HIGH);}
if (COLOR == 3)
{digitalWrite(LEDB, HIGH);}
delay(PSE);
randomSeed(analogRead(0));
COLOR = random(1,4);  // Select a random color.
}


if (COLOR == 1 && digitalRead(Button)==HIGH)// This loop is executed if the color is red.
{
digitalWrite(LEDGr,   LOW);
digitalWrite(LEDB,  LOW);
delay(PSE);
TME=millis(); // Time since this program has started (so Blue or Green loop included).
digitalWrite(LEDR, HIGH);

while (digitalRead(Button)==HIGH)// This loop runs untill you have released the button, hence the reaction time.
{delay(1);}
lcd.display();
RTME=millis()-TME; // Time since Led is Red, hence reaction time.
lcd.print("Reaction Time:");
lcd.setCursor(0,1);
lcd.print(RTME);
}

if (COLOR != 1) // This step is executed if the color is NOT red but the Push button was released (wrong action). 
{
lcd.print("Released too");
lcd.setCursor(0,1); // move to second line.
lcd.print("soon !!!");
tone(13,3000,1500);
delay(500);
noTone(13);
}


while (digitalRead(Button)==LOW) // The test does not re-start until the button is pushed once.
{delay(10);}

digitalWrite(LEDR, HIGH); // Resets all lights to begin again.
digitalWrite(LEDB, HIGH);
digitalWrite(LEDGr, HIGH);
lcd.clear();
lcd.print("Hold Button to");
lcd.setCursor(0,1);
lcd.print("start.");
int Time=0;
delay(1000);
}
]
{tone(13,1200,30);

There are conventions for where the { goes. Some like the { on the same line as the statement. Some, like me, prefer it on a new line.

There are NO conventions that allow for ANYTHING on the line after the {.

while (digitalRead(Button)==LOW) // The test does not start until the button is pushed (and held down).

Comments CAN precede the block of code. Nothing requires that put a lllooonnnggg comment on the same line as the statement, especially when the statement introduces a block.

Using
Tools
+
Auto
Format,
instead
of
jamming
all
the
code
in
column
1
is
truly
appreciated.

{digitalWrite(LEDGr, HIGH);}

The closing } ALWAYS goes on a new line.

As for what your problem is, I don't know. I gave up trying to read such poorly formatted code.

int Time=0;
delay(1000);
}

The code is truly hard to read, as PaulS says. A bit of time formatting it will help show up problems.

As for the above snippet, it appears to introduce a new variable, "Time" with the value 0, which immediately goes out of scope, so it may as well not exist.

Try to make your formatting more like, instead of:

if (Beep==1)
{tone(13,1600,350);
delay(750);
noTone(13);}

Do:

if (Beep == 1)
  {
  tone (13, 1600, 350);
  delay (750);
  noTone (13);
  }  // end if Beep == 1

Note the line breaks and extra spaces.

Awholelotofstuffwithoutspacesishardtoread.

Hi Guys, have reformatted code, trust this is more legible.

[ //After Dinner Reaction Time tester - created by Bertus52x11

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);

int backLight = 13;

int LEDR = 6; // Red Led pin 6

int LEDB = 7; // Blue Led pin 7

int LEDGr = 8; // Green Led pin 6

int Button = 1;

int COLOR; // variable Color

int Beep;

int PSE; // variable pause

int TME; // Time

int RTME = 0; // Reaction Time

void setup()
{

pinMode ( backLight, OUTPUT );

digitalWrite ( backLight, HIGH );

lcd.begin (16, 2 );

pinMode (LEDR, OUTPUT);

pinMode (LEDB, OUTPUT);

pinMode (LEDGr, OUTPUT);
pinMode (Button, INPUT);

digitalWrite (LEDR, HIGH); // All lights are switched “on”.

digitalWrite (LEDB, HIGH);

digitalWrite (LEDGr, HIGH);

}

void loop()

{

lcd.clear (); // Clear screen.

lcd.print ( “Hold Button to” );

lcd.setCursor ( 0, 1 ); // move to second line.

lcd.print (“start.”);

while (digitalRead ( Button ) == LOW ) // The test does not start until the button is pushed (and held down).

{tone ( 13, 1200, 30 );

delay ( 1400 );

noTone ( 13 );

}

lcd. clear ();

digitalWrite ( LEDR, LOW ); // switch off the "start"light.

digitalWrite ( LEDB, LOW );

digitalWrite ( LEDGr, LOW );

randomSeed ( analogRead (0) ); //Random noise from pin 0

COLOR = random ( 1, 4 ); // Generate a random color.

PSE = random ( 500, 600 ); // Select a random pause between the lights (to increase the surprise effect).

while ( COLOR!=1 && digitalRead ( Button ) == HIGH ) // This loop is repeated while color is Green or Blue AND button is held down.
{
digitalWrite ( LEDGr, LOW );

digitalWrite (LEDB, LOW );

delay ( PSE );

randomSeed ( analogRead (0) );

Beep = random ( 1, 4 ); // Select whether to beep or not (1 in 3 times).

PSE = random ( 750, 1200 ); // Select a random pause between the lights (to increase the surprise effect).

if ( Beep == 1 )
{
tone ( 13, 1600, 350 );

delay ( 750 );

noTone ( 13 );

}

if (COLOR == 2)

{

digitalWrite ( LEDGr, HIGH );

}

if (COLOR == 3)

{

digitalWrite ( LEDB, HIGH );

}

delay( PSE );

randomSeed ( analogRead (0) );

COLOR = random ( 1, 4 ); // Select a random color.

}

if ( COLOR == 1 && digitalRead ( Button ) ==HIGH ) // This loop is executed if the color is red.

{

digitalWrite ( LEDGr, LOW);

digitalWrite ( LEDB, LOW);

delay ( PSE );

TME= millis (); // Time since this program has started (so Blue or Green loop included).

digitalWrite ( LEDR, HIGH );

while (digitalRead ( Button) ==HIGH )// This loop runs untill you have released the button, hence the reaction time.

{

delay (1);

}

lcd. display ();

RTME = millis () -TME; // Time since Led is Red, hence reaction time.

lcd.print ( “Reaction Time:” ) ;

lcd.setCursor ( 0,1 );

lcd.print ( RTME );

}

if ( COLOR != 1 ) // This step is executed if the color is NOT red but the Push button was released (wrong action).

{

lcd. print (“Released too”);

lcd. setCursor ( 0, 1 ); // move to second line.

lcd. print (“soon !!!”);

tone ( 13, 3000, 1500 );

delay ( 500 );

noTone ( 13 );

}

while ( digitalRead (Button)== LOW ) // The test does not re-start until the button is pushed once.

{

delay ( 10 );

}

digitalWrite ( LEDR, HIGH ); // Resets all lights to begin again.

digitalWrite ( LEDB, HIGH );

digitalWrite ( LEDGr, HIGH );

lcd. clear ();

lcd. print ( “Hold Button to” );

lcd. setCursor ( 0, 1 );

lcd. print ( “start.” );

int Time = 0;

delay ( 1000 );

}
]

Not without code tags it isn't.

I didn't say to put a blank line between every line. Did my example do that? No.

Hi Guys, have reformatted code, trust this is more legible.

No, it’s not.

[co   //After Dinner Reaction Time tester - created by Bertus52x11


#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
int backLight = 13;
int LEDR = 6; // Red Led pin 6
int LEDB = 7; // Blue Led pin 7
int LEDGr = 8; // Green Led pin 6
int Button = 1;
int COLOR; // variable Color
int Beep;
int PSE; // variable pause 
int TME; // Time
int RTME = 0; // Reaction Time
void setup()
{ 
  pinMode ( backLight, OUTPUT ); 
  digitalWrite ( backLight, HIGH ); 
lcd.begin (16, 2 );
pinMode (LEDR, OUTPUT);
pinMode (LEDB, OUTPUT);
pinMode (LEDGr, OUTPUT);
pinMode (Button, INPUT);
digitalWrite (LEDR,  HIGH);   // All lights are switched "on".
digitalWrite (LEDB,  HIGH);
digitalWrite (LEDGr,  HIGH);
}
void loop()
{
  
lcd.clear ();  // Clear screen.
lcd.print ( "Hold Button to" );
lcd.setCursor ( 0, 1 ); // move to second line.
lcd.print ("start.");
while (digitalRead ( Button ) == LOW )   // The test does not start until the button is pushed (and held down).
{tone ( 13, 1200, 30 );
delay ( 1400 );
noTone ( 13 );
}

lcd. clear ();
digitalWrite ( LEDR, LOW );      // switch off the "start"light.
digitalWrite ( LEDB, LOW );
digitalWrite ( LEDGr, LOW );
randomSeed ( analogRead (0) );    //Random noise from pin 0
COLOR = random ( 1, 4 );       // Generate a random color.
PSE = random ( 500, 600 );      // Select a random pause between the lights (to increase the surprise effect).
while ( COLOR!=1 && digitalRead ( Button ) == HIGH )    // This loop is repeated while color is Green or Blue AND button is held down.
{
  
digitalWrite ( LEDGr,  LOW );
digitalWrite  (LEDB,  LOW );
delay ( PSE );
randomSeed ( analogRead (0) );
Beep = random ( 1, 4 );         // Select whether to beep or not (1 in 3 times).
PSE = random  ( 750, 1200 );          // Select a random pause between the lights (to increase the surprise effect).
if ( Beep == 1 )
{
  tone ( 13, 1600, 350 );   
delay ( 750 );
noTone ( 13 );
}

if (COLOR == 2)
{
 
digitalWrite ( LEDGr, HIGH );
}
if (COLOR == 3)
{
 
digitalWrite ( LEDB, HIGH );
}
delay( PSE );
randomSeed ( analogRead (0) );
COLOR = random ( 1, 4 );    // Select a random color.
}

if ( COLOR == 1 &&  digitalRead ( Button ) ==HIGH )      // This loop is executed if the color is red.
{
 
digitalWrite ( LEDGr,   LOW);
digitalWrite ( LEDB,  LOW);
delay ( PSE );
TME= millis ();           // Time since this program has started (so Blue or Green loop included).
digitalWrite  ( LEDR, HIGH );
while (digitalRead ( Button) ==HIGH )// This loop runs untill you have released the button, hence the reaction time.
 {  
 delay  (1);
 }

lcd. display ();
RTME = millis () -TME;          // Time since Led is Red, hence reaction time.
lcd.print ( "Reaction Time:" ) ;
lcd.setCursor ( 0,1 );
lcd.print ( RTME );
}

if ( COLOR != 1 )    // This step is executed if the color is NOT red but the Push button was released (wrong action).

{
  
lcd. print  ("Released too");

lcd. setCursor (  0, 1 );             // move to second line.

lcd. print  ("soon !!!");
tone ( 13, 3000, 1500 );

noTone ( 13 );
}

while  ( digitalRead (Button)== LOW )      // The test does not re-start until the button is pushed once.
{ 
  delay ( 10 );  
}
  
digitalWrite ( LEDR,  HIGH );                 // Resets all lights to begin again.
digitalWrite ( LEDB,  HIGH );
digitalWrite ( LEDGr,  HIGH );
lcd. clear ();
lcd. print  ( "Hold Button to" );
lcd. setCursor ( 0, 1 );
lcd. print ( "start." );
int  Time = 0;
delay ( 1000 );
} de]

I give up. You seem to have some reading comprehension issues oryouthinkthat

jammingsomecodetogetherwithridiculous amounts of white space in other

areas is ok.

It is not. Nothing goes on the line after the {. Nothing else goes on the same line as the }. Use white space appropriately - between functions, not as the first line of every function.

Use Tools + Auto Format!