7 segment led counter

Hey. I got a project with a 7 segment leds and 3 buttons to do a counter. Up button, adds 1 number and displays it with LEDs; Down Button susbstracts 1 number, if number is 9 and click up, it should go to 0, if number is 0 and click down, it should go to nine, finally A Button resets to 0.

I ve been coding all afternoon and finally got it to compile, I upload it to my Arduino but it won't work. It just displays the 0 and nothing happens when I click up or down button, I know they work because I ve used them for other programs

Could some one take a look on my code and tell me whats wrong, ill be very thankful since its my final project !!!1

Thanks in advance

int switchUpPin = 5;
int switchDownPin = 7;
int counter = 0;
int buttonUpState = 0;
int lastButtonUpState = 0;
int buttonDownState = 0;
int lastButtonDownState = 0;


void displayZero() {
  Serial.println("zero");
  digitalWrite (11, true);
  digitalWrite (13, true);
  digitalWrite (8, true);
  digitalWrite (9, true);
  digitalWrite (12, true);
  digitalWrite (A0, true);
}


void setup()
{
  Serial.begin(9600);

  Serial.begin(9600);
  pinMode(A0, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(switchUpPin, INPUT_PULLUP);
  pinMode(switchDownPin, INPUT_PULLUP);
}
void loop() {
  displayZero();
  
  buttonUpState = digitalRead(switchUpPin);
  buttonDownState = digitalRead(switchDownPin);

  //Detecting button press and getting the button status
  //Do this for the button up
  if (buttonUpState != lastButtonUpState)
  {
    if (buttonUpState == HIGH)
    {
      //Reset the counter to -1
      if (counter == 9)
      {
        counter = +1;
      }
      //Increase the counter by 1
      counter++;
      //Print the counter to the console and calling the function
      Serial.println(counter);
      changeNumber(counter);
      //Delaying by 250 ms
      delay(250);
    }
    else
    {
      Serial.println("OFF");
    }
    //Delay to avoid button bouncing
    delay(50);
  }

  //Do this for the button down
  if (buttonDownState != lastButtonDownState)
  {
    if (buttonDownState == HIGH)
    {
      //Set the counter to 10
      if (counter == 0)
      {
        counter = 10;
      }
      //Decreases the counter by 1
      counter--;
      ////Print the counter to the console and calling the function
      Serial.println(counter);
      changeNumber(counter);
      //Delaying by 250 ms
      delay(250);
    }
    else
    {
      Serial.println("OFF");
    }
    //Delay to avoid button bouncing
    delay(50);
  }
  //Calling the function changeNumber with the arg counter
  changeNumber(counter);
}

//The function to display the numbers
void changeNumber(int buttonPress)
{
  switch (buttonPress)
  {
    //number 0
    case 0:

      displayZero();
      break;
    //number 1
    case 1:
      Serial.println("one");
      digitalWrite (8, true);
      digitalWrite (11, true);
    case 2:
      Serial.println("two");
      digitalWrite (8, true);
      digitalWrite (10, true);
      digitalWrite (12, true);
      digitalWrite (A0, true);
      digitalWrite (13, true);
      break;
    case 3:
      Serial.println("three");
      digitalWrite (8, true);
      digitalWrite (12, true);
      digitalWrite (13, true);
      digitalWrite (A0, true);
      digitalWrite (10, true);
      break;
    case 4:
      Serial.println("four");
      digitalWrite (9, true);
      digitalWrite (8, true);
      digitalWrite (10, true);
      digitalWrite (11, true);
      break;
    case 5:
      Serial.println("five");
      digitalWrite (A0, true);
      digitalWrite (9, true);
      digitalWrite (10, true);
      digitalWrite (11, true);
      digitalWrite (13, true);
      break;
    case 6:
      Serial.println("six");
      digitalWrite (A0, true);
      digitalWrite (9, true);
      digitalWrite (10, true);
      digitalWrite (11, true);
      digitalWrite (12, true);
      digitalWrite (12, true);
      break;
    case 7:
      Serial.println("seven");
      digitalWrite (A0, true);
      digitalWrite (8, true);
      digitalWrite (10, true);
      digitalWrite (11, true);

      break;
    case 8:
      Serial.println("eight");
      digitalWrite (8, true);
      digitalWrite (9, true);
      digitalWrite (11, true);
      digitalWrite (10, true);
      digitalWrite (12, true);
      digitalWrite (A0, true);
      digitalWrite (13, true);
      break;
    case 9:
      Serial.println("nine");
      digitalWrite (A0, true);
      digitalWrite (9, true);
      digitalWrite (8, true);
      digitalWrite (10, true);
      digitalWrite (11, true);
      break;
  }
}

Where do you ever clear the segments? If you follow a 0 with a 1, you will still see a 0 unless you clear them.

Also, your button logic is backwards. If you're going to use internal pull-up resistors, button pressed = LOW.

Which brings up the subject of your schematic.

Find out what your program is doing by adding more Serial.print messages.

You say it does nothing... nothing on the serial monitor ?

try adding something like:

  //Detecting button press and getting the button status
  //Do this for the button up
  if (buttonUpState != lastButtonUpState)
  {
     Serial.print("we got here!");

Yours,
TonyWilk

P.S. you might like to look at where you change the value of lastButtonUpState...

aarg:
Where do you ever clear the segments? If you follow a 0 with a 1, you will still see a 0 unless you clear them.

how can id do it? im so sorry of bothering you with my stupid questions. Im a complete noob in this topics, I really hope you can help me

yeyo2129:
how can id do it?

Every 'case' in your 'switch (buttonPress)' construct should have 7 'digitalWrite()' function calls in it. Some will be 'digitalWrite(pin, LOW)' and some will be 'digitalWrite(pin, HIGH)', but there should always be 7 of them (i.e. one for each segment). And, see how I used 'LOW' and 'HIGH', not 'true' and 'false'. Those are boolean values.

Why do you have a 'displayZero()' function when your 'changeNumber()' function can already display ALL the numbers. Why not just use it?

Finally, the 'switch' construct is kind of a crude way of doing this. An array of bytes with one bit assigned to each segment would be much less aesthetically objectionable.

gfvalvo:
Every 'case' in your 'switch (buttonPress)' construct should have 7 'digitalWrite()' function calls in it. Some will be 'digitalWrite(pin, LOW)' and some will be 'digitalWrite(pin, HIGH)', but there should always be 7 of them (i.e. one for each segment). And, see how I used 'LOW' and 'HIGH', not 'true' and 'false'. Those are boolean values.

Why do you have a 'displayZero()' function when your 'changeNumber()' function can already display ALL the numbers. Why not just use it?

Finally, the 'switch' construct is kind of a crude way of doing this. An array of bytes with one bit assigned to each segment would be much less aesthetically objectionable.

Just did it and still not working

Show us a good schematic of your circuit.
Show us a good image of your wiring.

Always show us your ‘current’ compete sketch.
Use CTRL T to format the sketch.
Please use code tags.
Use the </> icon in the posting menu.

[code] Paste sketch here. [/code]

Here is the code with the correction

/Initialize the 7 segment pins
int A = 3;
int B = 2;
int C = 4;
int D = 5;
int DP = 7;
int E = 6;
int F = 8;
int G = 9;

//Initialize the push buttons pins, push buttons states, and the counter
int switchUpPin = 13;
int switchDownPin = 12;
int counter = 0;
int buttonUpState = 0;
int lastButtonUpState = 0;
int buttonDownState = 0;
int lastButtonDownState = 0;

void setup()
{
  Serial.begin(9600);

  pinMode(A, OUTPUT);
  pinMode(B, OUTPUT);
  pinMode(C, OUTPUT);
  pinMode(D, OUTPUT);
  pinMode(E, OUTPUT);
  pinMode(F, OUTPUT);
  pinMode(G, OUTPUT);
  pinMode(DP, OUTPUT);

  //Start with the deceimal point off
  digitalWrite(DP , HIGH);
}

void loop()
{
  //Getting the reads from the buttons
  buttonUpState = digitalRead(switchUpPin);
  buttonDownState = digitalRead(switchDownPin);

  //Detecting button press and getting the button status
  //Do this for the button up
  if (buttonUpState != lastButtonUpState)
  {
    if (buttonUpState == HIGH)
    {
      //Reset the counter to -1
      if (counter == 9)
      {
        counter = -1;
      }
      //Increase the counter by 1
      counter++;
      //Print the counter to the console and calling the function
      Serial.println(counter);
      changeNumber(counter);
      //Delaying by 250 ms
      delay(250);
    }
    else
    {
      Serial.println("OFF");
    }
    //Delay to avoid button bouncing
    delay(50);
  }

  //Do this for the button down
  if (buttonDownState != lastButtonDownState)
  {
    if (buttonDownState == HIGH)
    {
      //Set the counter to 10
      if (counter == 0)
      {
        counter = 10;
      }
      //Decreases the counter by 1
      counter--;
      ////Print the counter to the console and calling the function
      Serial.println(counter);
      changeNumber(counter);
      //Delaying by 250 ms
      delay(250);
    }
    else
    {
      Serial.println("OFF");
    }
    //Delay to avoid button bouncing
    delay(50);
  }
  //Calling the function changeNumber with the arg counter
  changeNumber(counter);
}

//The function to display the numbers
void changeNumber(int buttonPress)
{
  switch (buttonPress)
  {
    //number 0
    case 0:
      digitalWrite(A, LOW);
      digitalWrite(B, LOW);
      digitalWrite(C, LOW);
      digitalWrite(D, LOW);
      digitalWrite(E, LOW);
      digitalWrite(F, LOW);
      digitalWrite(G, HIGH);
      break;
    //number 1
    case 1:
      digitalWrite(A, HIGH);
      digitalWrite(B, LOW);
      digitalWrite(C, LOW);
      digitalWrite(D, HIGH);
      digitalWrite(E, HIGH);
      digitalWrite(F, HIGH);
      digitalWrite(G, HIGH);
      break;
    //number 2
    case 2:
      digitalWrite(A, LOW);
      digitalWrite(B, LOW);
      digitalWrite(C, HIGH);
      digitalWrite(D, LOW);
      digitalWrite(E, LOW);
      digitalWrite(F, HIGH);
      digitalWrite(G, LOW);
      break;
    //number 3
    case 3:
      digitalWrite(A, LOW);
      digitalWrite(B, LOW);
      digitalWrite(C, LOW);
      digitalWrite(D, LOW);
      digitalWrite(E, HIGH);
      digitalWrite(F, HIGH);
      digitalWrite(G, LOW);
      break;
    //number 4
    case 4:
      digitalWrite(A, HIGH);
      digitalWrite(B, LOW);
      digitalWrite(C, LOW);
      digitalWrite(D, HIGH);
      digitalWrite(E, HIGH);
      digitalWrite(F, LOW);
      digitalWrite(G, LOW);
      break;
    //number 5
    case 5:
      digitalWrite(A, LOW);
      digitalWrite(B, HIGH);
      digitalWrite(C, LOW);
      digitalWrite(D, LOW);
      digitalWrite(E, HIGH);
      digitalWrite(F, LOW);
      digitalWrite(G, LOW);
      break;
    //number 6
    case 6:
      digitalWrite(A, LOW);
      digitalWrite(B, HIGH);
      digitalWrite(C, LOW);
      digitalWrite(D, LOW);
      digitalWrite(E, LOW);
      digitalWrite(F, LOW);
      digitalWrite(G, LOW);
      break;
    //number 7
    case 7:
      digitalWrite(A, LOW);
      digitalWrite(B, LOW);
      digitalWrite(C, LOW);
      digitalWrite(D, HIGH);
      digitalWrite(E, HIGH);
      digitalWrite(F, HIGH);
      digitalWrite(G, HIGH);
      break;
    //number 8
    case 8:
      digitalWrite(A, LOW);
      digitalWrite(B, LOW);
      digitalWrite(C, LOW);
      digitalWrite(D, LOW);
      digitalWrite(E, LOW);
      digitalWrite(F, LOW);
      digitalWrite(G, LOW);
      break;
    //number 9
    case 9:
      digitalWrite(A, LOW);
      digitalWrite(B, LOW);
      digitalWrite(C, LOW);
      digitalWrite(D, HIGH);
      digitalWrite(E, HIGH);
      digitalWrite(F, LOW);
      digitalWrite(G, LOW);
      break;
  }
}

You never update lastButtonUpState or lastButtonDownState

larryd:
You never update lastButtonUpState or lastButtonDownState

What do you mena with that? How do I do it? Im really sorry and I apologize, its my first time into programming and I am a complete stupid, hope you can understand

if (buttonUpState != lastButtonUpState)
  {
     lastButtonUpState = buttonUpState;  // < - - - <<<

     if (buttonUpState == HIGH)
    {

.
.
.

if (buttonDownState != lastButtonDownState)
  {
     lastButtonDownState = buttonDownState;  // < - - - <<<

     if (buttonDownState == HIGH)
    {

Did you author this sketch?

larryd:

if (buttonUpState != lastButtonUpState)

{
    lastButtonUpState = buttonUpState;  // < - - - <<<

if (buttonUpState == HIGH)
   {

.
.
.

if (buttonDownState != lastButtonDownState)
 {
    lastButtonDownState = buttonDownState;  // < - - - <<<

if (buttonDownState == HIGH)
   {






Did you author this sketch?

yes, I just corrected with what you told me

What was the result of your changes?

Did you write this sketch?

larryd:
What was the result of your changes?

Did you write this sketch?

No results, still the same. The leds display a 0 but when I click the buttons nothing happens. Is there anything wrong in the code?

Did you write this sketch?

Show us a good schematic of your circuit.
Show us a good image of your wiring.

What is printed on the serial monitor with this version?

//Initialize the 7 segment pins
int A = 3;
int B = 2;
int C = 4;
int D = 5;
int DP = 7;
int E = 6;
int F = 8;
int G = 9;

//Initialize the push buttons pins, push buttons states, and the counter
int switchUpPin = 13;
int switchDownPin = 12;
int counter = 0;
int buttonUpState = 0;
int lastButtonUpState = 0;
int buttonDownState = 0;
int lastButtonDownState = 0;

void setup()
{
  Serial.begin(9600);

  pinMode(A, OUTPUT);
  pinMode(B, OUTPUT);
  pinMode(C, OUTPUT);
  pinMode(D, OUTPUT);
  pinMode(E, OUTPUT);
  pinMode(F, OUTPUT);
  pinMode(G, OUTPUT);
  pinMode(DP, OUTPUT);

  //Start with the deceimal point off
  digitalWrite(DP , HIGH);
}

void loop()
{
  //Getting the reads from the buttons
  buttonUpState = digitalRead(switchUpPin);
  buttonDownState = digitalRead(switchDownPin);

  //Detecting button press and getting the button status
  //Do this for the button up
  if (buttonUpState != lastButtonUpState)
  {
    lastButtonUpState = buttonUpState;
    if (buttonUpState == HIGH)
    {
      //Reset the counter to -1
      if (counter == 9)
      {
        counter = -1;
      }
      //Increase the counter by 1
      counter++;
      //Calling the function changeNumber with the arg counter
      changeNumber(counter);
    }
  }

  //Do this for the button down
  if (buttonDownState != lastButtonDownState)
  {
    lastButtonDownState = buttonDownState;
    if (buttonDownState == HIGH)
    {
      //Set the counter to 10
      if (counter == 0)
      {
        counter = 10;
      }
      //Decreases the counter by 1
      counter--;
      //Calling the function changeNumber with the arg counter
      changeNumber(counter);
     }
  }
}

//The function to display the numbers
void changeNumber(int buttonPress)
{
  switch (buttonPress)
  {
    //number 0
    case 0:
      Serial.println("0");
      digitalWrite(A, LOW);
      digitalWrite(B, LOW);
      digitalWrite(C, LOW);
      digitalWrite(D, LOW);
      digitalWrite(E, LOW);
      digitalWrite(F, LOW);
      digitalWrite(G, HIGH);
      break;
    //number 1
    case 1:
      Serial.println("1");
      digitalWrite(A, HIGH);
      digitalWrite(B, LOW);
      digitalWrite(C, LOW);
      digitalWrite(D, HIGH);
      digitalWrite(E, HIGH);
      digitalWrite(F, HIGH);
      digitalWrite(G, HIGH);
      break;
    //number 2
    case 2:
      Serial.println("2");
      digitalWrite(A, LOW);
      digitalWrite(B, LOW);
      digitalWrite(C, HIGH);
      digitalWrite(D, LOW);
      digitalWrite(E, LOW);
      digitalWrite(F, HIGH);
      digitalWrite(G, LOW);
      break;
    //number 3
    case 3:
      Serial.println("3");
      digitalWrite(A, LOW);
      digitalWrite(B, LOW);
      digitalWrite(C, LOW);
      digitalWrite(D, LOW);
      digitalWrite(E, HIGH);
      digitalWrite(F, HIGH);
      digitalWrite(G, LOW);
      break;
    //number 4
    case 4:
      Serial.println("4");
      digitalWrite(A, HIGH);
      digitalWrite(B, LOW);
      digitalWrite(C, LOW);
      digitalWrite(D, HIGH);
      digitalWrite(E, HIGH);
      digitalWrite(F, LOW);
      digitalWrite(G, LOW);
      break;
    //number 5
    case 5:
      Serial.println("5");
      digitalWrite(A, LOW);
      digitalWrite(B, HIGH);
      digitalWrite(C, LOW);
      digitalWrite(D, LOW);
      digitalWrite(E, HIGH);
      digitalWrite(F, LOW);
      digitalWrite(G, LOW);
      break;
    //number 6
    case 6:
      Serial.println("6");
      digitalWrite(A, LOW);
      digitalWrite(B, HIGH);
      digitalWrite(C, LOW);
      digitalWrite(D, LOW);
      digitalWrite(E, LOW);
      digitalWrite(F, LOW);
      digitalWrite(G, LOW);
      break;
    //number 7
    case 7:
      Serial.println("7");
      digitalWrite(A, LOW);
      digitalWrite(B, LOW);
      digitalWrite(C, LOW);
      digitalWrite(D, HIGH);
      digitalWrite(E, HIGH);
      digitalWrite(F, HIGH);
      digitalWrite(G, HIGH);
      break;
    //number 8
    case 8:
      Serial.println("8");
      digitalWrite(A, LOW);
      digitalWrite(B, LOW);
      digitalWrite(C, LOW);
      digitalWrite(D, LOW);
      digitalWrite(E, LOW);
      digitalWrite(F, LOW);
      digitalWrite(G, LOW);
      break;
    //number 9
    case 9:
      Serial.println("9");
      digitalWrite(A, LOW);
      digitalWrite(B, LOW);
      digitalWrite(C, LOW);
      digitalWrite(D, HIGH);
      digitalWrite(E, HIGH);
      digitalWrite(F, LOW);
      digitalWrite(G, LOW);
      break;
  }
}

It is not a good idea to use single letter variable names.
int A = 3;
Change to:
int segA = 3;
Use the correct 'type' for your variables.
int segA = 3;
Change to:
byte segA = 3;
A variable that will not change should be a constant.
byte segA = 3;
Change to:
const byte segA = 3;

larryd:
It is not a good idea to use single letter variable names.
int A = 3;
Change to:
int segA = 3;
Use the correct 'type' for your variables.
int segA = 3;
Change to:
byte segA = 3;
A variable that will not change should be a constant.
byte segA = 3;
Change to:
const byte segA = 3;

will that work? I can't really understand :confused:

I changed it.

This is my new code and still won't work

int switchUpPin = 5;
int switchDownPin = 7;
int counter = 0;
int buttonUpState = 0;
int lastButtonUpState = 0;
int buttonDownState = 0;
int lastButtonDownState = 0;


void displayZero() {
  Serial.println("zero");
  digitalWrite (11, HIGH);
  digitalWrite (13, HIGH);
  digitalWrite (8, HIGH);
  digitalWrite (9, HIGH);
  digitalWrite (12, HIGH);
  digitalWrite (A0, HIGH);
  digitalWrite(10, LOW);
}


void setup()
{
  Serial.begin(9600);

  Serial.begin(9600);
  pinMode(A0, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(switchUpPin, INPUT_PULLUP);
  pinMode(switchDownPin, INPUT_PULLUP);
}
void loop() {
  displayZero();

  buttonUpState = digitalRead(switchUpPin);
  buttonDownState = digitalRead(switchDownPin);

  //Detecting button press and getting the button status
  //Do this for the button up
  if (buttonUpState != lastButtonUpState)
  {
    if (buttonUpState == LOW)
    {
      //Reset the counter to -1
      if (counter == 9)
      {
        counter = -1;
      }
      //Increase the counter by 1
      counter++;
      //Print the counter to the console and calling the function
      Serial.println(counter);
      changeNumber(counter);
      //Delaying by 250 ms
      delay(250);
    }
    else
    {
      Serial.println("OFF");
    }
    //Delay to avoid button bouncing
    delay(50);
  }

  //Do this for the button down
  if (buttonDownState != lastButtonDownState)
  {
    if (buttonDownState == LOW)
    {
      //Set the counter to 10
      if (counter == 0)
      {
        counter = 10;
      }
      //Decreases the counter by 1
      counter--;
      ////Print the counter to the console and calling the function
      Serial.println(counter);
      changeNumber(counter);
      //Delaying by 250 ms
      delay(250);
    }
    else
    {
      Serial.println("OFF");
    }
    //Delay to avoid button bouncing
    delay(50);
  }
  //Calling the function changeNumber with the arg counter
  changeNumber(counter);
}

//The function to display the numbers
void changeNumber(int buttonPress)
{
  switch (buttonPress)
  {
    //number 0
    case 0:
      digitalWrite(A0, LOW);
      digitalWrite(8, LOW);
      digitalWrite(9, LOW);
      digitalWrite(11, LOW);
      digitalWrite(12, LOW);
      digitalWrite(13, LOW);
      digitalWrite(10, HIGH);
      break;
    //number 1
    case 1:
      Serial.println("one");
      digitalWrite (8, LOW);
      digitalWrite (11, LOW);
      digitalWrite(A0, HIGH);
      digitalWrite(9, HIGH);
      digitalWrite(10, HIGH);
      digitalWrite(12, HIGH);
      digitalWrite(13, HIGH);
    case 2:
      Serial.println("two");
      digitalWrite (8, LOW);
      digitalWrite (10, LOW);
      digitalWrite (12, LOW);
      digitalWrite (A0, LOW);
      digitalWrite (13, LOW);
      digitalWrite(9, HIGH);
      digitalWrite(11, HIGH);
      break;
    case 3:
      Serial.println("three");
      digitalWrite (8, LOW);
      digitalWrite (12, LOW);
      digitalWrite (13, LOW);
      digitalWrite (A0, LOW);
      digitalWrite (10, LOW);
      digitalWrite(9, HIGH);
      digitalWrite(11, HIGH);
      break;
    case 4:
      Serial.println("four");
      digitalWrite (9, LOW);
      digitalWrite (8, LOW);
      digitalWrite (10, LOW);
      digitalWrite (11, LOW);
      digitalWrite(A0, HIGH);
      digitalWrite(12, HIGH);
      digitalWrite(13, HIGH);
      break;
    case 5:
      Serial.println("five");
      digitalWrite (A0, LOW);
      digitalWrite (9, LOW);
      digitalWrite (10, LOW);
      digitalWrite (11, LOW);
      digitalWrite (13, LOW);
      digitalWrite(8, HIGH);
      digitalWrite(12, HIGH);
      break;
    case 6:
      Serial.println("six");
      digitalWrite (A0, LOW);
      digitalWrite (9, LOW);
      digitalWrite (10, LOW);
      digitalWrite (11, LOW);
      digitalWrite (12, LOW);
      digitalWrite (12, LOW);
      digitalWrite(8, HIGH);

      break;
    case 7:
      Serial.println("seven");
      digitalWrite (A0, LOW);
      digitalWrite (8, LOW);
      digitalWrite (10, LOW);
      digitalWrite (11, LOW);
      digitalWrite(9, HIGH);
      digitalWrite(12, HIGH);
      digitalWrite(13, HIGH);

      break;
    case 8:
      Serial.println("eight");
      digitalWrite (8, LOW);
      digitalWrite (9, LOW);
      digitalWrite (11, LOW);
      digitalWrite (10, LOW);
      digitalWrite (12, LOW);
      digitalWrite (A0, LOW);
      digitalWrite (13, LOW);
      break;
    case 9:
      Serial.println("nine");
      digitalWrite (A0, LOW);
      digitalWrite (9, LOW);
      digitalWrite (8, LOW);
      digitalWrite (10, LOW);
      digitalWrite (11, LOW);
      digitalWrite(12, HIGH);
      digitalWrite(13, HIGH);
      break;
  }
}