NOOB Servo problem

Hi there i am having an issue with a servo control. I want wen i press a button to increase 10degrees and store it.
I load it just fine on an arduino uno but when i run it the servo goes crazy.

void loop() 
{ 

  buttonState1 = digitalRead(signal1);    //enables signal read from pin 0v or 5v
  buttonState2 = digitalRead(signal2);    //enables signal read from pin 0v or 5v
  
  if (buttonState1 == HIGH) {
    pos1= pos1+10;
    servo1.write(pos1);
  }
  else {
    servo1.write(pos1);
  }
    
  Serial.println(pos1);

Where is the rest of your code?
What does the debug output look like?
How are the switches wired?

The rest of the code is to big with plenty of if's because i have 8 button 2 for each servo. 1 for increase 10 degrees and 1 to decrease 10 degrees for each servo. I don't get any error at compilation just don't reacts as i want. Already made all the statements but ony one servo in the Void loop. If the first works the rest will be done easily.
Servos attached to 6,9,10,11 and buttont to 2,3,4,5,7,8,12,13
MMA7361 attached to A0,A1,A2.
For now i want the servos to work then i'll try to make the code for the MMA7361
also i have int resPos = 40; as a reset possition

OK, see reply #1

I suggest that you post the complete program for one servo and answer the questions about debug output and switch wiring.

Here is the hole code. And what do you mean Debug? any pdf arduino turtorial for me to understand the IDE not with examples. i can see many examples but i can't understand everything.

#include <Servo.h> 
 
Servo servo1, servo2, servo3, servo4;  // create servo object to control a servo 

int resPos = 40;
int pos1 = 40;    // variable to store the servo position
int pos2 = 40;    // variable to store the servo position
int pos3 = 40;    // variable to store the servo position
int pos4 = 40;    // variable to store the servo position

const int signal1 = 2;    //input signal high or low
const int signal2 = 3;    //input signal high or low
const int signal3 = 4;    //input signal high or low
const int signal4 = 5;    //input signal high or low
const int signal5 = 7;    //input signal high or low
const int signal6 = 8;    //input signal high or low
const int signal7 = 12;   //input signal high or low

int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonState5 = 0;
int buttonState6 = 0;
int buttonState7 = 0;


void setup() 
{ 
  servo1.attach(6);  // attaches the servo on pin 6 to the servo object 
  servo2.attach(9);  // attaches the servo on pin 9 to the servo object 
  servo3.attach(10);  // attaches the servo on pin 10 to the servo object 
  servo4.attach(11);  // attaches the servo on pin 11 to the servo object 

  pinMode(signal1,INPUT);    //defines pin as input
  pinMode(signal2,INPUT);    //defines pin as input
  pinMode(signal3,INPUT);    //defines pin as input
  pinMode(signal4,INPUT);    //defines pin as input
  pinMode(signal5,INPUT);    //defines pin as input
  pinMode(signal6,INPUT);    //defines pin as input
  pinMode(signal7,INPUT);    //defines pin as input
  
  Serial.begin(9600);
} 
 
 
void loop() 
{ 

  buttonState1 = digitalRead(signal1);    //enables signal read from pin 0v or 5v
  buttonState2 = digitalRead(signal2);    //enables signal read from pin 0v or 5v
  buttonState3 = digitalRead(signal3);    //enables signal read from pin 0v or 5v
  buttonState4 = digitalRead(signal4);    //enables signal read from pin 0v or 5v
  buttonState5 = digitalRead(signal5);    //enables signal read from pin 0v or 5v
  buttonState6 = digitalRead(signal6);    //enables signal read from pin 0v or 5v
  buttonState7 = digitalRead(signal7);    //enables signal read from pin 0v or 5v
  
  if (buttonState1 == HIGH) {
    pos1 = pos1+10;
    servo1.write(pos1);
  }
  else if (buttonState2 == HIGH) {
   pos1 = pos1-10; 
   servo1.write(pos1);
  }
  else {
   servo1.write(pos1);
  }  
  Serial.println(pos1);
}

You've got serial debug prints - what do they tell you?

at the serial prints i am getting 1 rapidly increasing number

That's because you're incrementing all the time the switch is pressed, not when it becomes pressed., ie when it goes from not pressed to pressed.

It could also be because of a not well debounced button...

the number stop invreasing if i grnd the 2pin if i 5vthe 2pin i am not geting a response and with nothing done the servo goes all the way up

also i do not even have e button connected. i just conect direct pin2 to 5v with a ressiston in the mid

AWOL:
That's because you're incrementing all the time the switch is pressed, not when it becomes pressed., ie when it goes from not pressed to pressed.

what that suppose to mean? NNOOOOOBB here sorry. The examples are nice at all the turtorials but when it comes to a code creation :roll_eyes: :roll_eyes: :roll_eyes: :roll_eyes:

When you hold the button down the position variable increases each time through the loop() function. What you need to do is only increment the position when the button state changes from not pressed to pressed and not increment it if the button is held down.

Look at the state change example in the IDE to see how to do it. Basically you remember the state of the button the last time that it was read and only take action when it has changed, ie has been pressed.

Thanks i'll try put this in the code also.

Did this but the same result

#include <Servo.h> 
 
Servo servo1, servo2, servo3, servo4;  // create servo object to control a servo 

int resPos = 40;
int pos1 = 40;    // variable to store the servo position
int pos2 = 40;    // variable to store the servo position
int pos3 = 40;    // variable to store the servo position
int pos4 = 40;    // variable to store the servo position

const int signal1 = 2;    //input signal high or low
const int signal2 = 3;    //input signal high or low
const int signal3 = 4;    //input signal high or low
const int signal4 = 5;    //input signal high or low
const int signal5 = 7;    //input signal high or low
const int signal6 = 8;    //input signal high or low
const int signal7 = 12;   //input signal high or low

int buttonState1 = 0; // current state of the button
int buttonState2 = 0; // current state of the button
int buttonState3 = 0; // current state of the button
int buttonState4 = 0; // current state of the button
int buttonState5 = 0; // current state of the button
int buttonState6 = 0; // current state of the button
int buttonState7 = 0; // current state of the button

int lastButtonState1 = 0; // previous state of the button
int lastButtonState2 = 0; // previous state of the button
int lastButtonState3 = 0; // previous state of the button
int lastButtonState4 = 0; // previous state of the button
int lastButtonState5 = 0; // previous state of the button
int lastButtonState6 = 0; // previous state of the button
int lastButtonState7 = 0; // previous state of the button


void setup() 
{ 
  servo1.attach(6);  // attaches the servo on pin 6 to the servo object 
  servo2.attach(9);  // attaches the servo on pin 9 to the servo object 
  servo3.attach(10);  // attaches the servo on pin 10 to the servo object 
  servo4.attach(11);  // attaches the servo on pin 11 to the servo object 

  pinMode(signal1,INPUT);    //defines pin as input
  pinMode(signal2,INPUT);    //defines pin as input
  pinMode(signal3,INPUT);    //defines pin as input
  pinMode(signal4,INPUT);    //defines pin as input
  pinMode(signal5,INPUT);    //defines pin as input
  pinMode(signal6,INPUT);    //defines pin as input
  pinMode(signal7,INPUT);    //defines pin as input
  
  Serial.begin(9600);
} 
 
 
void loop() 
{ 

  buttonState1 = digitalRead(signal1);    //enables signal read from pin 0v or 5v
  buttonState2 = digitalRead(signal2);    //enables signal read from pin 0v or 5v
  buttonState3 = digitalRead(signal3);    //enables signal read from pin 0v or 5v
  buttonState4 = digitalRead(signal4);    //enables signal read from pin 0v or 5v
  buttonState5 = digitalRead(signal5);    //enables signal read from pin 0v or 5v
  buttonState6 = digitalRead(signal6);    //enables signal read from pin 0v or 5v
  buttonState7 = digitalRead(signal7);    //enables signal read from pin 0v or 5v
  
  if (buttonState1 != lastButtonState1) {
    if (buttonState1 == HIGH) {
    pos1 = pos1+10;
    servo1.write(pos1);
  }
   else {
   servo1.write(pos1);
  }  
  Serial.println(pos1);
}}

you need something that sets lastButtonState1 to buttonState1 after you've done your comparison.

at the state button example there is no such thing any example please?

Are you looking at the state change example?

In this section:

  // save the current state as the last state, 
  //for next time through the loop
  lastButtonState = buttonState;

put it in the if statement before pos=pos+10 and at the serial print i am getting 50 as a value with no change if button pressed.