7 segment display with buttons. + servo drive

int f = 13;
int g = 12;
int e = 11;
int d = 10;
int c = 7;
int b = 8;
int a = 9;   //7 Segment pin


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

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

  pinMode(f, OUTPUT);
  pinMode(g, OUTPUT);
  pinMode(e, OUTPUT);
  pinMode(d, OUTPUT);
  pinMode(c, OUTPUT);
  pinMode(b, OUTPUT);
  pinMode(a, OUTPUT);
  
  
}

void loop() 
{
    buttonUpState = digitalRead(switchUpPin);
  buttonDownState = digitalRead(switchDownPin);
 
  if (buttonUpState != lastButtonUpState) 
  {
    if (buttonUpState == HIGH) 
    {
      if(counter == 9)
      {
        counter = -1;
      }
      counter++;
      Serial.println(counter);
      changeNumber(counter);
      delay(300);
    }
    else
    {
        Serial.println("OFF");
    }
   delay(50);
  }
 
 
  if (buttonDownState != lastButtonDownState) 
  {
    if (buttonDownState == HIGH) 
    {
      if(counter == 0)
      {
        counter = 10;
      }
      counter--;
      Serial.println(counter);
      changeNumber(counter);
      delay(300);
    }
    else
    {
        Serial.println("OFF");
    }
   delay(50);
  }
  changeNumber(counter);
}
 
 
 
 
 
void changeNumber(int buttonPress)
{
  switch (buttonPress)
  {


 digitalWrite(a,1); 
 digitalWrite(b,1);  
 digitalWrite(c,1);  
 digitalWrite(d,1);  
 digitalWrite(e,1);  
 digitalWrite(f,1);  
 digitalWrite(g,0);   // 0
 break;
  
 digitalWrite(a,0); 
 digitalWrite(b,1);  
 digitalWrite(c,1);  
 digitalWrite(d,0);  
 digitalWrite(e,0);  
 digitalWrite(f,0);  
 digitalWrite(g,0);   // 1
 break;
  
 digitalWrite(a,1); 
 digitalWrite(b,1);  
 digitalWrite(c,0);  
 digitalWrite(d,1);  
 digitalWrite(e,1);  
 digitalWrite(f,0);  
 digitalWrite(g,1);   // 2
 break;
 
 digitalWrite(a,1); 
 digitalWrite(b,1);  
 digitalWrite(c,1);  
 digitalWrite(d,0);  
 digitalWrite(e,1);  
 digitalWrite(f,0);  
 digitalWrite(g,1);   // 3
 break; 
 
  digitalWrite(a,0); 
 digitalWrite(b,1);  
 digitalWrite(c,1);  
 digitalWrite(d,0);  
 digitalWrite(e,0);  
 digitalWrite(f,1);  
 digitalWrite(g,1);   // 4
 break;  

 digitalWrite(a,1); 
 digitalWrite(b,0);  
 digitalWrite(c,1);  
 digitalWrite(d,0);  
 digitalWrite(e,1);  
 digitalWrite(f,1);  
 digitalWrite(g,1);   // 5
 break;
  
 digitalWrite(a,0); 
 digitalWrite(b,0);  
 digitalWrite(c,1);  
 digitalWrite(d,1);  
 digitalWrite(e,1);  
 digitalWrite(f,1);  
 digitalWrite(g,1);   // 6
 break;
 
  digitalWrite(a,1); 
 digitalWrite(b,1);  
 digitalWrite(c,1);  
 digitalWrite(d,0);  
 digitalWrite(e,0);  
 digitalWrite(f,0);  
 digitalWrite(g,0);   // 7
 break;
 
}
}

I've recently attempted to make up a 7 segment counter with up and down buttons. The code above is where I am currently at. I have an issue where the buttons are wired up (image attached) and the serial monitor recognises button pushes but my 7 segment display does not work. Common cathode. Wired in with single resistor on Gnd and pins are as described in first paragraph of code. Any help would be much appreciated. I'l have many more questions i'm sure.

With the switch instruction you need at least one case

switch (var) {
  case 1:
    //do something when var equals 1
    break;
  case 2:
    //do something when var equals 2
    break;
  default:
    // if nothing else matches, do the default
    // default is optional
    break;
}

Too much code for something that doesn't work. I suggest that you write something smaller that lights a single segment of the display to prove to yourself that your wiring is correct.

Then maybe expand that to something that lights each of them in turn.

Thank you for the help. I have limited knowledge when it comes to code. I've really been cutting and pasting code together and trying to make it work but don't really know how to write it from scratch. Patrickrombaut. How do you mean needs one case and where do I add this into the sketch?

The individual codes I have spliced together will work fine on their own but once I join them it won't

How do you mean needs one case and where do I add this into the sketch?

switch/case is equivalent to

Given a value of x
if x equal 1
  do this
end if
if x equal 2
  do this
end if
if x equals 3
  do this
end if
etc, etc

The switch/case equivalent

switch based on the value of x
case 1
  do this
break
case 2
  do this
break
case 3
  do this
break

You have the switch command in your code but no cases

const int a = 8;  //For displaying segment "a"
const int b = 9;  //For displaying segment "b"
const int c = 4;  //For displaying segment "c"
const int d = 5;  //For displaying segment "d"
const int e = 6;  //For displaying segment "e"
const int f = 2;  //For displaying segment "f"
const int g = 13;  //For displaying segment "g"
bool bPress = false;
const int IncbuttonPin = 10;
const int DecbuttonPin = 11;
// Variables will change:
int buttonPushCounter = 0;   // counter for the number of button presses
int IncbuttonState = 0;         // current state of the button
int lastIncbuttonState = 0;     // previous state of the button
int DecbuttonState = 0;         // current state of the button
int lastDecbuttonState = 0;     // previous state of the button
void setup() {
  // put your setup code here, to run once:
  pinMode(a, OUTPUT);  //A
  pinMode(b, OUTPUT);  //B
  pinMode(c, OUTPUT);  //C
  pinMode(d, OUTPUT);  //D
  pinMode(e, OUTPUT);  //E
  pinMode(f, OUTPUT);  //F
  pinMode(g, OUTPUT);  //G
  pinMode( IncbuttonPin , INPUT_PULLUP );
  pinMode( DecbuttonPin , INPUT_PULLUP );
  Serial.begin(9600);  
  displayDigit(buttonPushCounter);  
}
void loop() {  
   IncbuttonState = digitalRead(IncbuttonPin);
   DecbuttonState = digitalRead(DecbuttonPin);
   checkIncButtonPress();
   checkDecButtonPress();  
  if( bPress ){
    bPress = false;
     turnOff();
     displayDigit(buttonPushCounter);
  }
   /*
  for(int i=0;i<10;i++)
 {
   displayDigit(i);
   delay(1000);
   turnOff();
 }
 */
}
void checkIncButtonPress()
{
   // compare the IncbuttonState to its previous state
  if (IncbuttonState != lastIncbuttonState) {
    // if the state has changed, increment the counter
    if (IncbuttonState == LOW) {
      // if the current state is HIGH then the button went from off to on:
      bPress = true;
      buttonPushCounter++;
      if( buttonPushCounter > 9) buttonPushCounter =0 ;
      Serial.println("on");      
    } else {
      // if the current state is LOW then the button went from on to off:
      Serial.println("off");
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state, for next time through the loop
  lastIncbuttonState = IncbuttonState;
}
void checkDecButtonPress()
{
   // compare the IncbuttonState to its previous state
  if (DecbuttonState != lastDecbuttonState) {
    // if the state has changed, increment the counter
    if (DecbuttonState == LOW) {
      // if the current state is HIGH then the button went from off to on:
      bPress = true;
      buttonPushCounter--;
      if( buttonPushCounter < 0) buttonPushCounter =9 ;
      Serial.println("on");      
    } else {
      // if the current state is LOW then the button went from on to off:
      Serial.println("off");
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state, for next time through the loop
  lastDecbuttonState = DecbuttonState;
}  
void displayDigit(int digit)
{
 //Conditions for displaying segment a
 if(digit!=1 && digit != 4)
 digitalWrite(a,HIGH);
 //Conditions for displaying segment b
 if(digit != 5 && digit != 6)
 digitalWrite(b,HIGH);
 //Conditions for displaying segment c
 if(digit !=2)
 digitalWrite(c,HIGH);
 //Conditions for displaying segment d
 if(digit != 1 && digit !=4 && digit !=7)
 digitalWrite(d,HIGH);
 //Conditions for displaying segment e 
 if(digit == 2 || digit ==6 || digit == 8 || digit==0)
 digitalWrite(e,HIGH);
 //Conditions for displaying segment f
 if(digit != 1 && digit !=2 && digit!=3 && digit !=7)
 digitalWrite(f,HIGH);
 if (digit!=0 && digit!=1 && digit !=7)
 digitalWrite(g,HIGH);
}
void turnOff()
{
  digitalWrite(a,LOW);
  digitalWrite(b,LOW);
  digitalWrite(c,LOW);
  digitalWrite(d,LOW);
  digitalWrite(e,LOW);
  digitalWrite(f,LOW);
  digitalWrite(g,LOW);
}

OK I have some code and a setup that works perfectly. What I would now like some assistance on is. How am I able to limit the numbers from 0-9 to 0-6. I would also like to know how to make it so the numbers don't cycle. Say if you were to keep pressing the down button it will only get to 0 and go no further/ return back to 9

 buttonPushCounter++;
      if( buttonPushCounter > 6) buttonPushCounter =6 ;
      Serial.println("on");      
    } else {
      // if the current state is LOW then the button went from on to off:
      Serial.println("off");
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state, for next time through the loop
  lastIncbuttonState = IncbuttonState;
}
void checkDecButtonPress()
{
   // compare the IncbuttonState to its previous state
  if (DecbuttonState != lastDecbuttonState) {
    // if the state has changed, increment the counter
    if (DecbuttonState == LOW) {
      // if the current state is HIGH then the button went from off to on:
      bPress = true;
      buttonPushCounter--;
      if( buttonPushCounter < 0) buttonPushCounter =0 ;
      Serial.println("on");      
    } else {
      // if the current state is LOW then the button went from on to off:
      Serial.println("off");

After looking at the code carefully, I've managed to fix this. Pretty obvious once I realised. Now for some guidance on how to attach a servo to move an adjustable amount with each button press. I'd like to b able to set the angle of the servo movement each push and have it move up and down with the LCD. How would I do this?

Servos usually have up to 180 degrees of movement. How much a particular one can manage is generally established by experiment. Once you know, you can use the map function to transform 0-9 into 20 to 160 (or whatever it turns out to be).

Don't try to power the servo from your Arduino.

I have limited knowledge when it comes to code. I've really been cutting and pasting code together and trying to make it work but don't really know how to write it from scratch.

Have you checked out the references, example sketches and tutorials on this site?

Yes I have been doing a lot of research and watching videos. I came here as I was having trouble understanding what I was doing wrong

#include <Servo.h>
Servo servo;


const int a = 8;  //For displaying segment "a"
const int b = 9;  //For displaying segment "b"
const int c = 4;  //For displaying segment "c"
const int d = 5;  //For displaying segment "d"
const int e = 6;  //For displaying segment "e"
const int f = 2;  //For displaying segment "f"
const int g = 13;  //For displaying segment "g"
bool bPress = false;
const int IncbuttonPin = 10;
const int DecbuttonPin = 11;
// Variables will change:
int buttonPushCounter = 0;   // counter for the number of button presses
int IncbuttonState = 0;         // current state of the button
int lastIncbuttonState = 0;     // previous state of the button
int DecbuttonState = 0;         // current state of the button
int lastDecbuttonState = 0;     // previous state of the button
void setup() {
  // put your setup code here, to run once:
  pinMode(a, OUTPUT);  //A
  pinMode(b, OUTPUT);  //B
  pinMode(c, OUTPUT);  //C
  pinMode(d, OUTPUT);  //D
  pinMode(e, OUTPUT);  //E
  pinMode(f, OUTPUT);  //F
  pinMode(g, OUTPUT);  //G
  pinMode( IncbuttonPin , INPUT_PULLUP );
  pinMode( DecbuttonPin , INPUT_PULLUP );
  Serial.begin(9600);  
  servo.attach(7);
  displayDigit(buttonPushCounter);  
}
void loop() {  
   IncbuttonState = digitalRead(IncbuttonPin);
   DecbuttonState = digitalRead(DecbuttonPin);
   checkIncButtonPress();
   checkDecButtonPress();  
  if( bPress ){
    bPress = false;
     turnOff();
     displayDigit(buttonPushCounter);
  }
   /*
  for(int i=0;i<10;i++)
 {
   displayDigit(i);
   delay(1000);
   turnOff();
 }
 */
}
void checkIncButtonPress()
{
   // compare the IncbuttonState to its previous state
  if (IncbuttonState != lastIncbuttonState) {
    // if the state has changed, increment the counter
    if (IncbuttonState == LOW) {
      // if the current state is HIGH then the button went from off to on:
      bPress = true;
      buttonPushCounter++;
      if( buttonPushCounter > 6) buttonPushCounter =6 ;
      Serial.println("on");      
    } else {
      // if the current state is LOW then the button went from on to off:
      Serial.println("off");
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state, for next time through the loop
  lastIncbuttonState = IncbuttonState;
}
void checkDecButtonPress()
{
   // compare the IncbuttonState to its previous state
  if (DecbuttonState != lastDecbuttonState) {
    // if the state has changed, increment the counter
    if (DecbuttonState == LOW) {
      // if the current state is HIGH then the button went from off to on:
      bPress = true;
      buttonPushCounter--;
      if( buttonPushCounter < 0) buttonPushCounter =0 ;
      Serial.println("on");      
    } else {
      // if the current state is LOW then the button went from on to off:
      Serial.println("off");
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state, for next time through the loop
  lastDecbuttonState = DecbuttonState;
}  
void displayDigit(int digit)
{
 //Conditions for displaying segment a
 if(digit!=2 && digit != 6)
 digitalWrite(a,HIGH);
 //Conditions for displaying segment b
 if(digit != 2)
 digitalWrite(b,HIGH);
 //Conditions for displaying segment c
 if(digit !=0 && digit !=5)
 digitalWrite(c,HIGH);
 //Conditions for displaying segment d
 if(digit !=0 && digit !=1 && digit !=2 && digit !=6)
 digitalWrite(d,HIGH);
 //Conditions for displaying segment e
 if(digit !=4 && digit !=6)
 digitalWrite(e,HIGH);
 //Conditions for displaying segment f
 if(digit != 2 && digit !=4 && digit!=5 && digit !=6)
 digitalWrite(f,HIGH);
 //Conditions for displaying segment g
 if (digit!=3 && digit!=6)
 digitalWrite(g,HIGH);
}
void turnOff()
{
  digitalWrite(a,LOW);
  digitalWrite(b,LOW);
  digitalWrite(c,LOW);
  digitalWrite(d,LOW);
  digitalWrite(e,LOW);
  digitalWrite(f,LOW);
  digitalWrite(g,LOW);
}

I've started putting the servo in. I have the following code from an old project that I would like to add to this. how do I get them to work together without errors? Do I have to void (something) at the end of the first code?

{
         bPress = true;
         // if the current state is HIGH then the button went from off to on:
         buttonPushCounter += 9;  // Servo degrees 
         if (buttonPushCounter > 180)
         {
            buttonPushCounter = 180;
         }

What is your resistor value? Driving all 7 segments at once with a single current limit resistor will yield varying brightnesses as the number of on-segments changes.

220 ohm i'm not getting any weird brightness differential. All segments are fine. I've got the LED and button part working as I want. I am only now trying to add a servo

I would think you could call a function to move the servo as part of this in loop().
Move one direction in an increment press, and the other direction on a decrement press.

  if( bPress ){
    bPress = false;
     turnOff();
     displayDigit(buttonPushCounter);
  }

Thank you for this. How would I also have a value that I can adjust for, say 10 degrees of servo travel each button push?

MattheWaye:
Yes I have been doing a lot of research and watching videos. I came here as I was having trouble understanding what I was doing wrong

So, in what way did those resources fail you? People learn in different ways, perhaps you're sort of looking in the wrong places...

Don't you have that servo travel amount already?

buttonPushCounter += 9; // Servo degrees

and perhaps -=9 for going the other direction with an apress button push?

Let me try this. I understand what all the individual commands do and can research. but I really struggle with the structure and how to build the code. I am new to programming and don't do this all that often

#include <Servo.h>
Servo servo;


const int a = 8;  //For displaying segment "a"
const int b = 9;  //For displaying segment "b"
const int c = 4;  //For displaying segment "c"
const int d = 5;  //For displaying segment "d"
const int e = 6;  //For displaying segment "e"
const int f = 2;  //For displaying segment "f"
const int g = 13;  //For displaying segment "g"
bool bPress = false;
const int IncbuttonPin = 10;
const int DecbuttonPin = 11;
// Variables will change:
int buttonPushCounter = 0;   // counter for the number of button presses
int IncbuttonState = 0;         // current state of the button
int lastIncbuttonState = 0;     // previous state of the button
int DecbuttonState = 0;         // current state of the button
int lastDecbuttonState = 0;     // previous state of the button
void setup() {
  // put your setup code here, to run once:
  pinMode(a, OUTPUT);  //A
  pinMode(b, OUTPUT);  //B
  pinMode(c, OUTPUT);  //C
  pinMode(d, OUTPUT);  //D
  pinMode(e, OUTPUT);  //E
  pinMode(f, OUTPUT);  //F
  pinMode(g, OUTPUT);  //G
  pinMode( IncbuttonPin , INPUT_PULLUP );
  pinMode( DecbuttonPin , INPUT_PULLUP );
  Serial.begin(9600);  
  servo.attach(7);
  displayDigit(buttonPushCounter);  
}
void loop() {  
   IncbuttonState = digitalRead(IncbuttonPin);
   DecbuttonState = digitalRead(DecbuttonPin);
   checkIncButtonPress();
   checkDecButtonPress();  
  if( bPress ){
    bPress = false;
     turnOff();
     displayDigit(buttonPushCounter);
  }
   if( bPress ){
    bPress = false;
     buttonPushCounter += 9;  // Servo degrees
     turnOff();
     displayDigit(buttonPushCounter);
     }
     if (buttonPushCounter > 180)
         {
            buttonPushCounter = 180;
             }
   /*
  for(int i=0;i<10;i++)
 {
   displayDigit(i);
   delay(1000);
   turnOff();
 }
 */
}
void checkIncButtonPress()
{
   // compare the IncbuttonState to its previous state
  if (IncbuttonState != lastIncbuttonState) {
    // if the state has changed, increment the counter
    if (IncbuttonState == LOW) {
      // if the current state is HIGH then the button went from off to on:
      bPress = true;
      buttonPushCounter++;
      if( buttonPushCounter > 6) buttonPushCounter =6 ;
      Serial.println("on");      
    } else {
      // if the current state is LOW then the button went from on to off:
      Serial.println("off");
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state, for next time through the loop
  lastIncbuttonState = IncbuttonState;
}
void checkDecButtonPress()
{
   // compare the IncbuttonState to its previous state
  if (DecbuttonState != lastDecbuttonState) {
    // if the state has changed, increment the counter
    if (DecbuttonState == LOW) {
      // if the current state is HIGH then the button went from off to on:
      bPress = true;
      buttonPushCounter--;
      if( buttonPushCounter < 0) buttonPushCounter =0 ;
      Serial.println("on");      
    } else {
      // if the current state is LOW then the button went from on to off:
      Serial.println("off");
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state, for next time through the loop
  lastDecbuttonState = DecbuttonState;
}  
void displayDigit(int digit)
{
 //Conditions for displaying segment a
 if(digit!=2 && digit != 6)
 digitalWrite(a,HIGH);
 //Conditions for displaying segment b
 if(digit != 2)
 digitalWrite(b,HIGH);
 //Conditions for displaying segment c
 if(digit !=0 && digit !=5)
 digitalWrite(c,HIGH);
 //Conditions for displaying segment d
 if(digit !=0 && digit !=1 && digit !=2 && digit !=6)
 digitalWrite(d,HIGH);
 //Conditions for displaying segment e
 if(digit !=4 && digit !=6)
 digitalWrite(e,HIGH);
 //Conditions for displaying segment f
 if(digit != 2 && digit !=4 && digit!=5 && digit !=6)
 digitalWrite(f,HIGH);
 //Conditions for displaying segment g
 if (digit!=3 && digit!=6)
 digitalWrite(g,HIGH);
}
void turnOff()
{
  digitalWrite(a,LOW);
  digitalWrite(b,LOW);
  digitalWrite(c,LOW);
  digitalWrite(d,LOW);
  digitalWrite(e,LOW);
  digitalWrite(f,LOW);
  digitalWrite(g,LOW);
}

This is that I have. The servo is glitchy and uncontrollable. signal pin is in digital pin 7 and the servo is powered by a 5 v power supply. Thoughts?

In my attempts to get the servo working I've tried splicing in multiple versions of servo code. The code below does not show any errors then you compile the sketch but once uploaded and in use the servo portion does not work. I have absolutely no idea what I'm doing wrong.

#include <Servo.h>
Servo myservo;
int angle =180;    // initial angle  for servo
int angleStep =10;
#define LEFT 10   // pin 10 is connected to left button
#define RIGHT  11  // pin 11 is connected to right button 

const int a = 8;  //For displaying segment "a"
const int b = 9;  //For displaying segment "b"
const int c = 4;  //For displaying segment "c"
const int d = 5;  //For displaying segment "d"
const int e = 6;  //For displaying segment "e"
const int f = 2;  //For displaying segment "f"
const int g = 13;  //For displaying segment "g"
bool bPress = false;
const int IncbuttonPin = 10;
const int DecbuttonPin = 11;
// Variables will change:
int buttonPushCounter = 0;   // counter for the number of button presses
int IncbuttonState = 0;         // current state of the button
int lastIncbuttonState = 0;     // previous state of the button
int DecbuttonState = 0;         // current state of the button
int lastDecbuttonState = 0;     // previous state of the button

void setup() {
  // put your setup code here, to run once:
  pinMode(a, OUTPUT);  //A
  pinMode(b, OUTPUT);  //B
  pinMode(c, OUTPUT);  //C
  pinMode(d, OUTPUT);  //D
  pinMode(e, OUTPUT);  //E
  pinMode(f, OUTPUT);  //F
  pinMode(g, OUTPUT);  //G
  pinMode( IncbuttonPin , INPUT_PULLUP );
  pinMode( DecbuttonPin , INPUT_PULLUP );
  Serial.begin(9600);  
  myservo.attach(7);
  pinMode(LEFT,INPUT_PULLUP); // assign pin as input for Left button
  pinMode(RIGHT,INPUT_PULLUP);// assing pin as input for right button
  myservo.write(angle);// send servo to the middle at 90 degrees
  displayDigit(buttonPushCounter);  
}

void loop()
{  

   IncbuttonState = digitalRead(IncbuttonPin);
   DecbuttonState = digitalRead(DecbuttonPin);
   checkIncButtonPress();
   checkDecButtonPress();
     if( bPress ){
    bPress = false;
     turnOff();
     displayDigit(buttonPushCounter); 
  }
  

    /*
  for(int i=0;i<10;i++)
 {
   displayDigit(i);
   delay(1000);
   turnOff();
 }
 */
}
void checkIncButtonPress()
{
  
   // compare the IncbuttonState to its previous state
  if (IncbuttonState != lastIncbuttonState) {
    // if the state has changed, increment the counter
    if (IncbuttonState == LOW) {
      // if the current state is HIGH then the button went from off to on:
      bPress = true;
      buttonPushCounter++;
      if( buttonPushCounter > 6) buttonPushCounter =6 ;
      Serial.println("on");      
    } else {
      // if the current state is LOW then the button went from on to off:
      Serial.println("off");
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state, for next time through the loop
  lastIncbuttonState = IncbuttonState;
}
void checkDecButtonPress()
{
   // compare the IncbuttonState to its previous state
  if (DecbuttonState != lastDecbuttonState) {
    // if the state has changed, increment the counter
    if (DecbuttonState == LOW) {
      // if the current state is HIGH then the button went from off to on:
      bPress = true;
      buttonPushCounter--;
      if( buttonPushCounter < 0) buttonPushCounter =0 ;
      Serial.println("on");      
    } else {
      // if the current state is LOW then the button went from on to off:
      Serial.println("off");
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state, for next time through the loop
  lastDecbuttonState = DecbuttonState;
}  
void displayDigit(int digit)
{
 //Conditions for displaying segment a
 if(digit!=2 && digit != 6)
 digitalWrite(a,HIGH);
 //Conditions for displaying segment b
 if(digit != 2)
 digitalWrite(b,HIGH);
 //Conditions for displaying segment c
 if(digit !=0 && digit !=5)
 digitalWrite(c,HIGH);
 //Conditions for displaying segment d
 if(digit !=0 && digit !=1 && digit !=2 && digit !=6)
 digitalWrite(d,HIGH);
 //Conditions for displaying segment e
 if(digit !=4 && digit !=6)
 digitalWrite(e,HIGH);
 //Conditions for displaying segment f
 if(digit != 2 && digit !=4 && digit!=5 && digit !=6)
 digitalWrite(f,HIGH);
 //Conditions for displaying segment g
 if (digit!=3 && digit!=6)
 digitalWrite(g,HIGH);
}
void turnOff()
{
  digitalWrite(a,LOW);
  digitalWrite(b,LOW);
  digitalWrite(c,LOW);
  digitalWrite(d,LOW);
  digitalWrite(e,LOW);
  digitalWrite(f,LOW);
  digitalWrite(g,LOW);

      }
void digitalwrite() {
  
while(digitalRead(RIGHT) == LOW){
if (angle > 0 && angle <= 180) {
      angle = angle - angleStep;
       if(angle < 0){
        angle = 0;
       }else{
      myservo.write(angle); // move the servo to desired angle
     
       }
    }
    
  delay(100); // waits for the servo to get there
  }//
 

 while(digitalRead(LEFT) == LOW){
if (angle >= 0 && angle <= 180) {
      angle = angle + angleStep;
      if(angle >180){
        angle =180;
       }else{
      myservo.write(angle); // move the servo to desired angle
      
       }
    }
    
  delay(100); // waits for the servo to get there
      }// 
   }