start servo motor by push button with user select mode

hi to all,

below code is very useful from marcello.romani in http://forum.arduino.cc/index.php?topic=124707.0 please help me…
i want add one servo motor and one more push button (total 2) 1 push button for select mode
2nd push button for start the servo, main objective is, user select mode every LEDs have 1 mode, LED1 represent for 2 minute, LED2 is represent 5 minute, the servo will start rotate 90deg and return back, time interval according to mode selected.

int switchPin = 2;              // switch is connected to pin 2
int led1Pin = 8;
int led2pin = 9;

int val;                        // variable for reading the pin status
int val2;                       // variable for reading the delayed status
int buttonState;                // variable to hold the button state
int Mode = 0;              // What mode is the light in?
boolean modeChanged = false;
const int NUM_MODES = 4;


void setup() {
    pinMode(switchPin, INPUT);    // Set the switch pin as input
    pinMode(led1Pin, OUTPUT);
    pinMode(led2pin, OUTPUT);
    buttonState = digitalRead(switchPin);   // read the initial state
}


void loop(){
    val = digitalRead(switchPin);      // read input value and store it in val
    delay(10);                         // 10 milliseconds is a good amount of time
    val2 = digitalRead(switchPin);     // read the input again to check for bounces
    if (val == val2) {                 // make sure we got 2 consistant readings!
        if (val != buttonState) {          // the button state has changed!
            if (val == LOW) {                // check if the button is pressed
                Mode++;
                if (Mode >= NUM_MODES) {
                    Mode = 0;
                }
                modeChanged = true;
            }
        }
        buttonState = val;                 // save the new state in our variable
    }

    if (modeChanged) {
        modeChanged = false;

        // Now do whatever the lightMode indicates
        switch(Mode) {
        case 0:
            digitalWrite(led1Pin, LOW);
            digitalWrite(led2pin, LOW);
            break;

        case 1:
            digitalWrite(led1Pin, HIGH);
            digitalWrite(led2pin, LOW);
            break;

        case 2:
            digitalWrite(led1Pin, LOW);
            digitalWrite(led2pin, HIGH);

        case 3:
            digitalWrite(led1Pin, HIGH);
            digitalWrite(led2pin, HIGH);
        }
    }
}

And what have you tried? Are you expecting someone to code that for you?

Got this notification

nalsur8 quoted you in the post (private topic)

do you have a question?

need your help please, i added some component but start button not function
please review whats wrong i’m done.

#include <Servo.h>
Servo myservo1;
int switchPin = 2;      // switch is connected to pin 2
int switchPinStart = 7; // start pushbutton
int pressStart = 0;
int led1Pin = 3;
int led2pin = 4;
int led3pin = 5;
int intervalmode = 0;
int deelayy = 100;
int pos = 0;

int val;                        // variable for reading the pin status
int val2;                       // variable for reading the delayed status
int buttonState;                // variable to hold the button state
int Mode = 0;              // What mode is the light in?
boolean modeChanged = false;
const int NUM_MODES = 7;


void setup() {
  myservo1.attach(9);
  pinMode(switchPinStart, INPUT);
  digitalWrite(7, HIGH); // enable pin pullup
    pinMode(switchPin, INPUT);    // Set the switch pin as input
    pinMode(led1Pin, OUTPUT);
    pinMode(led2pin, OUTPUT);
    pinMode(led3pin, OUTPUT);
    buttonState = digitalRead(switchPin);   // read the initial state
}


void loop(){
    val = digitalRead(switchPin);      // read input value and store it in val
    delay(10);                         // 10 milliseconds is a good amount of time
    val2 = digitalRead(switchPin);     // read the input again to check for bounces
    if (val == val2) {                 // make sure we got 2 consistant readings!
        if (val != buttonState) {          // the button state has changed!
            if (val == LOW) {                // check if the button is pressed
                Mode++;
                if (Mode >= NUM_MODES) {
                    Mode = 0;
                }
                modeChanged = true;
            }
        }
        buttonState = val;                 // save the new state in our variable
    }

    if (modeChanged) {
        modeChanged = false;

        // Now do whatever the lightMode indicates
        switch(Mode) {
        case 0: //off
            digitalWrite(led1Pin, LOW);
            digitalWrite(led2pin, LOW);
            digitalWrite(led3pin, LOW);
            break;

        case 1:
            digitalWrite(led1Pin, HIGH);
            digitalWrite(led2pin, LOW);
            digitalWrite(led3pin, LOW);
            intervalmode = 1;
            deelayy = 2000;
            break;

        case 2:
            digitalWrite(led1Pin, LOW);
            digitalWrite(led2pin, HIGH);
            digitalWrite(led3pin, LOW);
            intervalmode = 2;
            deelayy = 3000;
          break;

        case 3:
            digitalWrite(led1Pin, LOW);
            digitalWrite(led2pin, LOW);
            digitalWrite(led3pin, HIGH);
            intervalmode = 3;
            deelayy = 4000;
          break;

        case 4:
            digitalWrite(led1Pin, HIGH);
            digitalWrite(led2pin, HIGH);
            digitalWrite(led3pin, LOW);
            intervalmode = 4;
            deelayy = 5000;
            break;

        case 5:
            digitalWrite(led1Pin, HIGH);
            digitalWrite(led2pin, LOW);
            digitalWrite(led3pin, HIGH);
            intervalmode = 5;
            deelayy = 6000;
            break;

         case 6:
            digitalWrite(led1Pin, LOW);
            digitalWrite(led2pin, HIGH);
            digitalWrite(led3pin, HIGH);
            intervalmode = 6;
            deelayy = 7000;
            break; 
        }//switch mode
    }//if (modechange)
    pressStart = digitalRead(switchPinStart);
    if (pressStart == LOW){
      if ( intervalmode == 1){
    for (pos = 0; pos <= 45; pos +=1) {
      myservo1.write(pos);
      delay(10);
    }
    delay(deelayy);
    for (pos = 45; pos >= 0; pos -= 1) {
      myservo1.write(pos);
      delay(5);
    }
      }
       if ( intervalmode == 2){
    for (pos = 0; pos <= 45; pos +=1) {
      myservo1.write(pos);
      delay(10);
    }
    delay(deelayy);
    for (pos = 45; pos >= 0; pos -= 1) {
      myservo1.write(pos);
      delay(5);
    }
      }
       if ( intervalmode == 3){
    for (pos = 0; pos <= 45; pos +=1) {
      myservo1.write(pos);
      delay(10);
    }
    delay(deelayy);
    for (pos = 45; pos >= 0; pos -= 1) {
      myservo1.write(pos);
      delay(5);
    }
      }
       if ( intervalmode == 4){
    for (pos = 0; pos <= 45; pos +=1) {
      myservo1.write(pos);
      delay(10);
    }
    delay(deelayy);
    for (pos = 45; pos >= 0; pos -= 1) {
      myservo1.write(pos);
      delay(5);
    }
      }
       if ( intervalmode == 5){
    for (pos = 0; pos <= 45; pos +=1) {
      myservo1.write(pos);
      delay(10);
    }
    delay(deelayy);
    for (pos = 45; pos >= 0; pos -= 1) {
      myservo1.write(pos);
      delay(5);
    }
      }
       if ( intervalmode == 6){
    for (pos = 0; pos <= 45; pos +=1) {
      myservo1.write(pos);
      delay(10);
    }
    delay(deelayy);
    for (pos = 45; pos >= 0; pos -= 1) {
      myservo1.write(pos);
      delay(5);
    }
      }
    }
}//loop
  pinMode(switchPinStart, INPUT);
  digitalWrite(7, HIGH); // enable pin pullup
    pinMode(switchPin, INPUT);    // Set the switch pin as input

Why turn the internal pullup resistor on for one switch but not the other?

Why not use INPUT_PULLUP and dispense with the digitalWrite()?