Programming Help

Hello Everyone,

I am thinking about starting a project, but I only know very little about writing code. In the code I will need the Arduino to move a servo motor probably about 20 degrees when a button is pushed. I will need the servo to keep moving 20 degrees every time the button is pushed and then reset to the beginning once it can't move 20 degrees anymore. If anyone knows how to write this code, please let me know.

-Thank You Everyone!

If anyone knows how to write this code, please let me know.

I do. I'm not sure how that helps you, though.

There are plenty of examples of how to read a switch. There are plenty of examples of how to move a servo. It's not rocket science to figure out that you need to put the "move the servo" code in the "if switch becomes pressed" block.

Very simple servo button code you can study.

//zoomkat servo button test 12-29-2011

#include <Servo.h>
int button1 = 4; //button pin, connect to ground to move servo
int press1 = 0;
int button2 = 5; //button pin, connect to ground to move servo
int press2 = 0;
Servo servo1;

void setup()
{
  pinMode(button1, INPUT);
  pinMode(button2, INPUT);
  servo1.attach(7);
  digitalWrite(4, HIGH); //enable pullups to make pin high
  digitalWrite(5, HIGH); //enable pullups to make pin high
}

void loop()
{
  press1 = digitalRead(button1);
  if (press1 == LOW)
  {
    servo1.write(170);
  }    
  
  press2 = digitalRead(button2);
  if (press2 == LOW)
  {
    servo1.write(10);
  }
}

Thank you so much for your help!

@PaulS I'm sorry if I didn't make myself clear enough but as zoomkat understood I was hoping somebody would be kind enough to tell me how to write the code or help me write it. Thanks for trying to help though.

I've found it very helpful when I can find sample code that sort of does what I need if I dont know how, then modify it.

Just serach it up on goolgle

As opposed to you posting a link? Or maybe spelling stuff correctly? No thanks.

You're hijacking the thread and you can't post code properly.
How to post code properly

Pete

PaulS if you know how to write the code could you give it to me please? I do not understand the coding.