Code for using serial monitor to reset count

Hey guys, I'm new here so forgive me if I ask stuff in a wrong way.. I need help with something.
I have a code to enable my LED 7 segment display to count to 9 and restart from 0 again. However, I now need to provide an input from the serial monitor which will begin the count all over again from 0 regardless of which number it is at. Any ideas or editing I could do to my code? Please be patient with me, I am new to the programming world :slight_smile:
My code for the count is given below. I tried beginning the serial in the setup and putting some if statements but did not do it successfully. Kindly advise how I could achieve my task. Thanks :slight_smile:
/*

  • This program counts from 0 to 9 on the LCD display
  • Goes from 0 to 9 and back down to zero
  • Authors: Fahmid Chowdhury and Maxim Selvamanoharan
  • Version 1.1
  • Last updated by Fahmid Chowdhury

The circuit:

  • 5V voltage supply for the LED
  • Output is using digital pins 7 to 13
    */

// Pins connected to LED display
// give the pins an individual name:
int a = 12;
int b = 13;
int c = 9;
int d = 8;
int e = 7;
int f = 11;
int g = 10;

// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pins as an output.
pinMode(a, OUTPUT);
pinMode(b, OUTPUT);
pinMode(c, OUTPUT);
pinMode(d, OUTPUT);
pinMode(e, OUTPUT);
pinMode(f, OUTPUT);
pinMode(g, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
zero(); //Name of the output which is displayed
delay(1000); //duration that the number is displayed for
one();
delay(1000);
two();
delay(1000);
three();
delay(1000);
four();
delay(1000);
five();
delay(1000);
six();
delay(1000);
seven();
delay(1000);
eight();
delay(1000);
nine();
delay(1000);
eight();
delay(1000);
seven();
delay(1000);
six();
delay(1000);
five();
delay(1000);
four();
delay(1000);
three();
delay(1000);
two();
delay(1000);
one();
delay(1000);
zero();
delay(1000);
}
void zero(){ //Name of output defined
digitalWrite(a, LOW); // turn the LED to display 0
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, HIGH);
}
void one(){
digitalWrite(a, HIGH); // turn the LED on to display 1
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
}
void two(){
digitalWrite(a, LOW); // turn the LED on to display 2
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, HIGH);
digitalWrite(g, LOW);
}
void three(){
digitalWrite(a, LOW); // turn the LED on to display 3
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, LOW);
}
void four(){
digitalWrite(a, HIGH); // turn the LED on to display 4
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
}
void five(){
digitalWrite(a, LOW); // turn the LED on to display 5
digitalWrite(b, HIGH);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, HIGH);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
}
void six(){
digitalWrite(a, LOW); // turn the LED on to display 6
digitalWrite(b, HIGH);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
}
void seven(){
digitalWrite(a, LOW); // turn the LED on to display 7
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
}
void eight(){
digitalWrite(a, LOW); // turn the LED on to display 8
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
}
void nine(){
digitalWrite(a, LOW); // turn the LED on to display 9
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, HIGH);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
}

Kindly advise how I could achieve my task.

You could start with reading the "Before you post..." sticky at the top of the forum, and post your code correctly.

You could have some code that actually reads from the serial port.

You could read, understand, and embrace the blink without delay philosophy. Those delay()s will make reading from the serial port, and resetting the counter, unresponsive.

First learn how to write code without using delay!. (you can't do what you want if your using it) and then learn how to read from Serial!

Mark