Where is mistake?

Hi,
first i would like to say that I’m new and I’m from Poland 8) (so I don’t know english so well and I make mistakes- sorry). I want my project to look like this. I would like tow have 3 modes. When I press a button, I will switch them (1—>2—>3—>1—>2—>3—>1…etc.). 1 press= 1 switch. When I would have 1 mode I would like to turn LED(1) and be able to use servo(1) controled by potentiometer. When I would have 2 mode I would like to turn another LED(2) and be able to use (another) servo (2) controled by the same potentiometer. When I would have 3 mode I would like to turn another LED(3) and be able to use potentiometer to control turning on and off another LED(4).
I did a sketch but it doesn’t work. Does anybody know what’s wrong with it and try to help me with fixing it?
Thanks.
My sketch:

//Project hubert123
 #include <Servo.h>
 
 Servo servoLeft;  // create servo object to control a servo
 Servo myservo;  // create servo object to control a servo
 int val; // potentiometer
 const int potpin = A0; //potentiometer
 int buttonPin = 2;   // connect the button to pin 2
 int ledPin1 = 3;     // connect the first LED to pin 3- mode 1
 int ledPin2 = 4;  // connect the second LED to pin 4 - mode 2
 int ledPin3 = 5; // connect the third Led to pin 5- mode 3
 const int LED = 6; // connect the third led to pin 6
 int oldFlashMode = 0;        // a variable to keep track of what mode the flashlight is in...
                      //         0: mode 1
                      //         1: mode 2
                      //         2: mode 3
 int newFlashMode = 0;
 int newButtonState;  // a variable to keep track of the button's state this time through the loop
 int oldButtonState;  // a variable to keep track of the button's previous state
                      // (so we can compare to newButtonState to detect a "new" press)
                      
int sensorValue = 0;        // value read from the pot
int outputValue = 0;        // value output to the PWM (analog out)
 
 void setup()
 {
   servoLeft.attach(9);
   myservo.attach(10);
   pinMode(ledPin1,OUTPUT);// set the pins to the correct modes here
   pinMode(ledPin2,OUTPUT);
   pinMode(ledPin3,OUTPUT);
   pinMode(LED,OUTPUT);
   pinMode(buttonPin,INPUT);
   Serial.begin(9600); // "unremark" this line to use the serial monitor for debugging
  
 }
 
 void loop()
 {
   newButtonState=digitalRead(buttonPin);
   if(newButtonState == HIGH && oldButtonState == LOW)// put a logic test here to detect if the button has just been pushed)
 {
     if(oldFlashMode == 0)// put a logic test here to see if oldFlashMode is 0)
     {
       digitalWrite(ledPin1, HIGH);
       digitalWrite(ledPin2,LOW);
       digitalWrite(ledPin3, LOW);
       delay(100);
        
       val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
       val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180)
       servoLeft.write(val);                  // sets the servo position according to the scaled value
       delay(15);                           // waits for the servo to get there
      
       newFlashMode = 1;  // put some code here to turn one LED on and update the newFlashMode to 1
    
     // put someting here mode 1
    
     }
     if(oldFlashMode == 1)// put a logic test here to see if oldFlashMode is 1)
     {
      digitalWrite(ledPin1, LOW);
       digitalWrite(ledPin2,HIGH);
       digitalWrite(ledPin3, LOW);
       delay(100);
      
       val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
       val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180)
       myservo.write(val);                  // sets the servo position according to the scaled value
       delay(15);                           // waits for the servo to get there
      
       newFlashMode = 2; // put some code here to turn both LEDs on and update the newFlashMode to 2]
    
     // put something here mode 2
    
     }
     if(oldFlashMode == 2)// put a logic test here to see if oldFlashMode is 2)
     {
       digitalWrite(ledPin1,LOW);
       digitalWrite(ledPin2,LOW);
        digitalWrite(ledPin3, HIGH);
       delay(100);
      
      // read the analog in value:
  sensorValue = analogRead(potpin);            
  // map it to the range of the analog out:
  outputValue = map(sensorValue, 0, 1023, 0, 255);  
  // change the analog out value:
  analogWrite(LED, outputValue);          

    delay(2);              
      
     }
    
     oldFlashMode = newFlashMode; // now that the mode has been incremented, update variables
   }
  
   oldButtonState = newButtonState; // update the state of the button
 }

I think the circuit should look like this:
http://postimg.org/image/gydgf1gl9/

project physics circuit.bmp (1.09 MB)

Well what is the code doing?

Added:
You should maybe clean up the code just a little bit more. Maybe instead of using IF statements, try using case statements.

const byte Button = 2;
byte ButtonState;
byte last = LOW;
int count = 0;

void setup() {
  Serial.begin(9600);
  pinMode(Button, INPUT);
}

void loop() {
  ButtonState = digitalRead(Button);
  
  if(ButtonState && ButtonState != last) {
    count++;
    Serial.println(count);
  }
  
  if(count >=3) {
    count = 0;
  }
 switch( count ) {
   case 0: 
      Serial.println("Hello");
      break;

   case 1:
      Serial.println("How are you");
      break;
 
   case 2:
      Serial.println("Good day");
      break;

   default:
    // Add a default option here if needed
   }

  last = ButtonState;
}

Two things: please put your code into a "code" block instead of a "quote" block. It's the button with the hash sign (#) to the left of the quote button. Second, you say what your code should do, and you say it "doesn't work," but what does it do? How specifically doesn't it work?

Some additional small comments:

 const int potpin = A0; //potentiometer
 int buttonPin = 2;   // connect the button to pin 2
 int ledPin1 = 3;     // connect the first LED to pin 3- mode 1
 int ledPin2 = 4;  // connect the second LED to pin 4 - mode 2
 int ledPin3 = 5; // connect the third Led to pin 5- mode 3
 const int LED = 6; // connect the third led to pin 6

All of these can be const byte. Will save a small amount of memory.

pinMode(buttonPin,INPUT);

You seem to have wired up your switch with a pulldown resistor, but it is simpler and usually preferable to use the Arduino's internal pullup resistors instead. To do this, use pinMode(buttonPin, INPUT_PULLUP). Then wire the switch as follows: Input_Pin -> switch -> Ground. The pin will read HIGH when the switch is not pressed and LOW when the switch is pressed, which is the reverse of how a pulldown resistor would work. This eliminates any need for external pullup/down resistors.

 int oldFlashMode = 0;        // a variable to keep track of what mode the flashlight is in...
                      //         0: mode 1
                      //         1: mode 2
                      //         2: mode 3

Here, you would do well to define these modes with constant names that describe their function. Since I don't know what the function is, I'll just give an example with "mode 1," "mode 2," and "mode 3".

const byte outputMode1 = 0;
const byte outputMode2 = 1;
const byte outputMode3 = 2;

byte oldFlashMode = outputMode1;

This means that you never have to remember the actual numerical value of the mode constants. Just use the descriptive name. The code becomes much easier to read and debug.

Whenever you have repetitive blocks of code like this:

       val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
       val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180)
       myservo.write(val);                  // sets the servo position according to the scaled value
       delay(15);                           // waits for the servo to get there

You should put them into a function and call the function instead of re-writing the code over and over again.

void syncServoToPot(Servo s, byte pinNum)
{
  int a = analogRead(pinNum);
  a = map(a, 0, 1023, 0, 179);
  s.write(a);
  delay(15);
}

Ok, thank you for your help and for your advices. Actually I found where was the mistake. I don’t know why it didn’t work. I changed my code a little bit. If someone wants to have it, i will add it. Maybe it would be helpful for another people.

/*
  hubert123
   
 */
 #include <Servo.h>
 
 Servo servoLeft;
 Servo servoRight;   
 int val;
 const int potpin = A0; 
 int buttonPin = 2;   
 const int ledPin1 = 3;     
 const int ledPin2 = 4; 
 const int ledPin3 = 5; 
 const int LED = 6; 
 int oldFlashMode = 0;        // a variable to keep track of what mode the flashlight is in...
                      //         0: mode 1
                      //         1: mode 2
                      //         2: mode 3
 int newFlashMode = 0;
 int newButtonState;  // a variable to keep track of the button's state this time through the loop
 int oldButtonState;  // a variable to keep track of the button's previous state 
                      // (so we can compare to newButtonState to detect a "new" press)
                      
int sensorValue = 0;        
int outputValue = 0;        

 void setup()
 {
   servoLeft.attach(9); 
   servoRight.attach(10); 
   pinMode(ledPin1,OUTPUT);
   pinMode(ledPin2,OUTPUT);
   pinMode(ledPin3,OUTPUT);
   pinMode(LED,OUTPUT);
   pinMode(buttonPin,INPUT);
   pinMode(potpin,INPUT);
   Serial.begin(9600); 
   
 }
 
 void loop()
 {
   newButtonState=digitalRead(buttonPin);
   Serial.print("new button state  ");
   Serial.println(newButtonState);
   if(newButtonState == HIGH && oldButtonState == LOW)
 {
     if(oldFlashMode == 0)
     {
       digitalWrite(ledPin1, HIGH);
       digitalWrite(ledPin2,LOW);
       digitalWrite(ledPin3, LOW);
       Serial.print("mode    ");
       Serial.println(oldFlashMode);
       delay(1000);
       
       do
      { 
       
       val = analogRead(potpin);            
       val = map(val, 0, 1023, 0, 179);    
         Serial.print("val  ");
       Serial.println(val);
       servoLeft.write(val);                  
       delay(15);                           
      }while (digitalRead(buttonPin) == LOW);
    
       newFlashMode = 1;  
     
   
     
     }
     if(oldFlashMode == 1)
     {
      digitalWrite(ledPin1, LOW);
       digitalWrite(ledPin2,HIGH);
       digitalWrite(ledPin3, LOW);
       Serial.print("mode    ");
       Serial.println(oldFlashMode);
       delay(1000);
       
       do
       {
       val = analogRead(potpin);
       val = map(val, 0, 1023, 0, 179);  
      Serial.print("val  ");
       Serial.println(val); 
       servoRight.write(val);                
       delay(15);                         
       }while (digitalRead(buttonPin) == LOW);
       
       newFlashMode = 2; 
       
     }
     if(oldFlashMode == 2)
     {
       digitalWrite(ledPin1,LOW);
       digitalWrite(ledPin2,LOW);
        digitalWrite(ledPin3, HIGH);
        Serial.print("mode    ");
       Serial.println(oldFlashMode);
       delay(1000);
       
   do
{   
  val = analogRead(potpin);
  Serial.print("val  ");
       Serial.println(val); 
  digitalWrite(LED, HIGH); 
  delay(val);              
  digitalWrite(LED, LOW);  
  delay(val);                  
}while (digitalRead(buttonPin) == LOW);

  delay(2);    
  
        newFlashMode = 0; 
     }
    
     oldFlashMode = newFlashMode; 
   }
   
   oldButtonState = newButtonState; 
 }

Pressing CTRL+T in the Arduino development environment will auto-indent your code. It will look much nicer and be easier to read. As so:

/*
  hubert123
 
 */
#include <Servo.h>

Servo servoLeft;
Servo servoRight;   
int val;
const int potpin = A0; 
int buttonPin = 2;   
const int ledPin1 = 3;     
const int ledPin2 = 4; 
const int ledPin3 = 5; 
const int LED = 6; 
int oldFlashMode = 0;        // a variable to keep track of what mode the flashlight is in...
//         0: mode 1
//         1: mode 2
//         2: mode 3
int newFlashMode = 0;
int newButtonState;  // a variable to keep track of the button's state this time through the loop
int oldButtonState;  // a variable to keep track of the button's previous state 
// (so we can compare to newButtonState to detect a "new" press)

int sensorValue = 0;        
int outputValue = 0;        

void setup()
{
  servoLeft.attach(9); 
  servoRight.attach(10); 
  pinMode(ledPin1,OUTPUT);
  pinMode(ledPin2,OUTPUT);
  pinMode(ledPin3,OUTPUT);
  pinMode(LED,OUTPUT);
  pinMode(buttonPin,INPUT);
  pinMode(potpin,INPUT);
  Serial.begin(9600); 

}

void loop()
{
  newButtonState=digitalRead(buttonPin);
  Serial.print("new button state  ");
  Serial.println(newButtonState);
  if(newButtonState == HIGH && oldButtonState == LOW)
  {
    if(oldFlashMode == 0)
    {
      digitalWrite(ledPin1, HIGH);
      digitalWrite(ledPin2,LOW);
      digitalWrite(ledPin3, LOW);
      Serial.print("mode    ");
      Serial.println(oldFlashMode);
      delay(1000);

      do
      { 

        val = analogRead(potpin);            
        val = map(val, 0, 1023, 0, 179);    
        Serial.print("val  ");
        Serial.println(val);
        servoLeft.write(val);                  
        delay(15);                           
      }
      while (digitalRead(buttonPin) == LOW);

      newFlashMode = 1;  



    }
    if(oldFlashMode == 1)
    {
      digitalWrite(ledPin1, LOW);
      digitalWrite(ledPin2,HIGH);
      digitalWrite(ledPin3, LOW);
      Serial.print("mode    ");
      Serial.println(oldFlashMode);
      delay(1000);

      do
      {
        val = analogRead(potpin);
        val = map(val, 0, 1023, 0, 179);  
        Serial.print("val  ");
        Serial.println(val); 
        servoRight.write(val);                
        delay(15);                         
      }
      while (digitalRead(buttonPin) == LOW);

      newFlashMode = 2; 

    }
    if(oldFlashMode == 2)
    {
      digitalWrite(ledPin1,LOW);
      digitalWrite(ledPin2,LOW);
      digitalWrite(ledPin3, HIGH);
      Serial.print("mode    ");
      Serial.println(oldFlashMode);
      delay(1000);

      do
      {   
        val = analogRead(potpin);
        Serial.print("val  ");
        Serial.println(val); 
        digitalWrite(LED, HIGH); 
        delay(val);              
        digitalWrite(LED, LOW);  
        delay(val);                  
      }
      while (digitalRead(buttonPin) == LOW);

      delay(2);    
      newFlashMode = 0; 
    }
    oldFlashMode = newFlashMode; 
  }
  oldButtonState = newButtonState; 
}