Looping the code back to the start

Hi

I have made my code but I need it to restart to the begining.

 #include <LiquidCrystal.h>;
unsigned long startTime;
unsigned long stopTime;
unsigned long elapsedTime; 
unsigned long Time;
boolean started = false;
boolean stopped = false;
int startPin = 9;                 
int stopPin = 8;
const int numRows = 2;
const int numCols = 16;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{
pinMode(stopPin, INPUT); 
pinMode(startPin, INPUT);
 digitalRead;
  Serial.begin(9600);
 {
   
void loop();
{
  
   if(digitalRead(startPin) == HIGH) // The sensor has been activated
{
   started = true;         // If this is ture start the timer
   startTime = micros(); // States when the senor has been crossed
} 

  if(digitalRead(stopPin) == HIGH) // The sensor has been activated
{
   stopped = true;         // If this is ture start the timer
   stopTime = micros(); // States when the senor has been crossed
} 
if(started && stopped)
{
   elasped = stopTime - startTime; // How long did that take?
   Serial.print("Elapsed time, in microseconds: ");
   Serial.println(elapsed);

   started = false;  // Reset so the senors can be tripped again
   stopped = false;
} 
Serial.print("Elapsed time, in seconds: ");
lcd.print("Elapsed time, in seconds: ");

Theres my code what do I do?

Thanks

Your { } are not balanced.

At the end of the first #include line, remove the semicolon.

At the end of setup(), right after the Serial.begin(9600); line, turn { into }.

You don't need the first digitalRead; line, it is doing nothing here.

Remove the semicolon at the end of the line void loop().

Add a } to the end of your sketch. This balances out the { after void loop().

Void loop will repeat over and over al by it self, you don't need to do anything.

You are missing a } at the end :slight_smile:

Thank you I have done that but now its giving an error of "elasped wasn't declared in this scope.

What do I do?

 #include <LiquidCrystal.h>
unsigned long startTime;
unsigned long stopTime;
unsigned long elapsedTime; 
unsigned long Time;
boolean started = false;
boolean stopped = false;
int startPin = 9;                 
int stopPin = 8;
const int numRows = 2;
const int numCols = 16;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{
pinMode(stopPin, INPUT); 
pinMode(startPin, INPUT);
  digitalRead; 
  Serial.begin(9600);
}
   
void loop()
{
  
   if(digitalRead(startPin) == HIGH) // The sensor has been activated
{
   started = true;         // If this is ture start the timer
   startTime = micros(); // States when the senor has been crossed
} 

  if(digitalRead(stopPin) == HIGH) // The sensor has been activated
{
   stopped = true;         // If this is ture start the timer
   stopTime = micros(); // States when the senor has been crossed
} 
if(started && stopped)
{
  elasped = stopTime - startTime; // How long did that take?
   Serial.print("Elapsed time, in microseconds: ");
   Serial.println(elapsed);

   started = false;  // Reset so the senors can be tripped again
   stopped = false;
} 
Serial.print("Elapsed time, in seconds: ");
lcd.print("Elapsed time, in seconds: ");
}

What do I do?

Either declare "elapsed", or change "elapsed" to "elapsedTime".